matching and replacing across line breaks

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Dec 15 09:56:25 AEST 1989


In article <12329 at burdvax.PRC.Unisys.COM> lang at PRC.Unisys.COM (Francois-Michel Lang) writes:
>Can anyone provide a solution to this problem,
>preferably using sed or awk or some such utility:

>I want to operate on a file in such a way that every occurrence of
>"foo" at the end of one line followed by "bar" at the beginning of the
>next line is replaced by "quux".  I have a way to do this using sed
>that works *most* of the time, but there are certain cases in which
>it fails.

Since I personally feel every UNIX site should have "sam" on hand,
here's my solution:

sam -d file_to_be_edited <<!
,x/foo\nbar/c/quux/
w
q
!

You can also do this easily with TECO, but I'm more reluctant to
recommend that you take the trouble to acquire TECO.

Both "sam" and TECO are available from the UNIX System ToolChest.
I also distribute a merged version "sam" with support for DMD, MTG,
SunTools, and X bitmap front ends to sites that have valid "sam"
licensing.  (I don't know how much of that is available in the
current ToolChest version.)



More information about the Comp.unix.questions mailing list