Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!homxb!houxm!mhuxt!mhuxm!mhuxo!ulysses!allegra!alice!lem From: lem@alice.UUCP Newsgroups: comp.unix.questions Subject: Re: Embedded newlines in sed Message-ID: <6716@alice.uUCp> Date: Thu, 12-Mar-87 15:50:35 EST Article-I.D.: alice.6716 Posted: Thu Mar 12 15:50:35 1987 Date-Received: Sat, 14-Mar-87 07:02:25 EST Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 62 Keywords: sed embedded newlines To match patterns spread over more than one line, you have to get more than one line of the file into the pattern space. the 'N' command reads the next line of the file into the pattern space, appending it to whatever is already there, and separating it from what is there by a '\n' character (012). Patterns in the script are matched against whatever is in the pattern-space. The following script should find consecutive groups of lines: one two three and turn them into: one, two, three just copying everything else in the input file. $q N $q /^.*\n.*\n/!N /^one\ntwo\nthree$/!{ P D } s/\n/, /g If the above script is in the file sedscript, and the input file: one two one two three four five (without the leading tabs) is in input, the command sed -f sedscript input shoud produce one two one, two, three four five as output (again, without leading tabs). It works with the 8th (9th) Edition sed that I support; subtle changes were introduced at UCB and in System V (different in the two cases); mail me if you have trouble. Lee McMahon --- ihnp4!research!lem