On Thursday 15 May 2008 02:40:09 pm Eric Peterson wrote:
> I'm trying to get sed to update a bunch of my source files with a
> common comment and maintain the indent. I can get the line inserted
> above the regexp match but it has no indent. So I'm trying to capture
> the amount of indent using backreferences but it's not working. Any
> ideas?
>
> Here's what I have now:
>
> sed /^\(    *\)put comment above this line/i\\1### My comment
>
> Currently the regexp works and the line is inserted above "put comment
> above this line", but the back reference "\1" doesn't get evaluated.
>
> Eric

Most likely you aren't matching the whitespace because it isn't 5 or more 
literal spaces.  I'd substitute [[:space:]] for it and maybe wrap the 
expression in '' to eliminate some of the backslashes giving you...

sed -e '/^([[:space:]]*)put comment above this line/i\\1### My comment'

It's also worth noting your sed may take a flag to interpret EREs and things 
like [[:space:]], I don't have gnu sed handy here to test.

-- 
Thanks,

Josh Paetzel

PGP: 8A48 EF36 5E9F 4EDA 5A8C 11B4 26F9 01F1 27AF AECB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part.
Url : http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20080517/8150021e/attachment.pgp