Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!udel!burdvax!lang From: lang@PRC.Unisys.COM (Francois-Michel Lang) Newsgroups: comp.unix.questions Subject: matching and replacing across line breaks Keywords: sed awk Message-ID: <12329@burdvax.PRC.Unisys.COM> Date: 14 Dec 89 14:41:00 GMT Sender: news@PRC.Unisys.COM Lines: 58 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. Specifically, on input --- a s d xxxfoo barfoo baryyy q w e foo bar t y last foo line --- I want to produce --- a s d xxxquuxquuxyyy q w e quux t y last foo line --- The sed script I have (see below) won't handle multiple consecutive occurrences of "foo\nbar", and it also has a nasty habit of discarding the very last input line if it happens to contain a "foo". /foo/ { N s/foo\nbar/quux/ } ---------------------------------------------------------------------------- Francois-Michel Lang Paoli Research Center, Unisys lang@prc.unisys.com (215) 648-7256 Dept of Comp & Info Science, U of PA lang@linc.cis.upenn.edu (215) 898-9511