[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quick sed question



To follow up to myself, a quick regex lesson...

>     sed 's/^.*\.\(.*\)-.*$/\1/'

The pattern we're matching is '^.*\.\(.*\)-.*$'.  Broken down, that's

    ^    match the beginning of the line
    .    match any character
    *    repeat last match any number of times
    \.   literal "."
    \(   begin grouping
    .*   any number of any character
    \)   end grouping
    -    literal "-"
    .*   any number of any character
    $    match the end of the line

Now, we're replacing that with '\1'.  That matches the first grouped
pattern (the first thing between "\(" and "\)", in other words).

For reference, the same thing in perl would be

    s/^.*\.(.*)-.*$/$1/

although \1 (instead of $1) will work (it's deprecated though).

Steve
-- 
steve@silug.org           | Southern Illinois Linux Users Group
(618)398-7320             | See web site for meeting details.
Steven Pritchard          | http://www.silug.org/
-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.