[oclug] Search & replace Q.
patsmith at pobox.com
Wed Jul 14 12:34:06 EDT 2004
Jon Earle wrote:
> On Wed, 14 Jul 2004, Patrick Smith wrote:
>>sed -e '/^OBJECT / s/STYLE="thisstyle"/STYLE="thatstyle"/' ...
>>which applies the change only to lines beginning with OBJECT and a space.
> I'm going to look there now. The problem though is, the STYLE attribute
> could be on the second line, or other subsequent line.
You may want to try the two-address form. For example,
sed -e '/^OBJECT/,/^$/ s/STYLE="thisstyle"/STYLE="thatstyle"/' ...
would apply the change in blocks of lines where the first line of the
block starts with OBJECT and the last line of the block is empty.
Outside of such blocks, the change would not be applied.
More information about the OCLUG