Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.questions Subject: Re: Sed -- deleting to line BEFORE regexp match Message-ID: <957@philmds.UUCP> Date: 20 Feb 89 20:18:34 GMT References: <3296@uhccux.uhcc.hawaii.edu> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 49 In article <3296@uhccux.uhcc.hawaii.edu> lupton@uhccux.uhcc.hawaii.edu (Robert Lupton) writes: |I have a patch generator (a script using diff -c, of course), and I want |to exclude the patches for certain files. So I want to delete all lines |from | |diff -c -r old_file new_file |... |diff -c -r OLD_FILE NEW_FILE | |(but keeping the second diff line), using sed. [some lines removed] If the second address expression would uniquely identify the last line of a range of lines, it is easy: /firstexpr/,/lastexpr/{ /lastexpr/!{ etc. } } However, in this case the first line matches the second address expression, so we have to do something else. The following will only need one extra line for each file you want to 'exclude' in the patch: sed " /^diff/{ : again /new_file1$/b del /new_file2$/b del (etc.) /new_fileN$/b del b nodel : del n /^diff/b again b del : nodel }" |Also, I couldn't make this work using csh (it complains about unmatched "), |only with the Bourne shell. Csh doesn't like newlines in quoted strings; you'll have to quote them (using a backslash character). Leo.