Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-10-31 08:23:49

troy d. straszheim wrote:
> I figured out what GNU sed's first complaint was, it doesn't like
> this:
> macroname=`cat $file | grep '^//[] []*MACRO:' | sed 's/.*MACRO:[]
> []*\([]_A-Z0-9[]*\).*/\1/'`
> but it does like this:
> macroname=`cat $file | grep '^//[] []*MACRO:' | sed 's/.*MACRO:[]
> []*\([_A-Z0-9]*\).*/\1/'`

Doug, what are you trying to do here?

If you're trying to extract "foo" from a line
then you should do it as:

macroname=`sed -n '
/^[TAB ]*MACRO:/{
    # Remove everything up to the beginning of
    # the first word after MACRO
    s/.*MACRO:[TAB ]*//
    # Remove everything after this word and
    # print to stdout.
}' "$file"`

where TAB is a literal TAB character Control-VControl-I.

There's no need to invoke three process when you need only one and
it's good practise to quote variables that expand to file names.

Let me know if the above doesn't fit the bill and, if I can't figure
it out myself I'll take it to the sed-users list.


Boost list run by bdawes at, gregod at, cpdaniel at, john at