[kwlug-disc] Block level search and replace

Kyle Spaans 3lucid at gmail.com
Wed Feb 23 20:24:37 EST 2011


On Wed, Feb 23, 2011 at 5:28 PM, Insurance Squared Inc.
<gcooke at insurancesquared.com> wrote:
> In the loop below, what happens (if anything) if the information wraps
> lines, i.e. instead of
>
>        for f in *.html ; do
>                sed 'above expr'<  "$f">  "/something/newset/$f"
>        done
>
> We have
>
>        for f in *.html ; do
>                sed 'above
>                        expr'
>        <  "$f">  "/something/newset/$f"
>        done
>
> Does that change anything?

I think in that case you want to use the sed commands ``n'' and ``N''
for appending the next line into the pattern space. See a better
explanation here[1]. So if you are confident that they will be on
adjacent lines, you can have something like (I'll just quote the sed
script, as if you'd put it in a file):

/<body>/ {
  N;
  /<center>/ {
    s,<center>,...,
  }
}

1 - http://www.grymoire.com/Unix/Sed.html#uh-51




More information about the kwlug-disc mailing list