Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!ucsd!nosc!humu!uhccux!lupton From: lupton@uhccux.uhcc.hawaii.edu (Robert Lupton) Newsgroups: comp.unix.questions Subject: Sed -- deleting to line BEFORE regexp match Message-ID: <3296@uhccux.uhcc.hawaii.edu> Date: 19 Feb 89 22:54:21 GMT Organization: University of Hawaii Lines: 30 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. I can do it in awk rather clumsily, but as I'm already sed'ing the diff output I'd rather just add another -e. The following works as part of the pipeline, but surely there's a better way! You are only allowed to use the string `new_file' only once, so I'll be able to add other files that I want to ignore. sed -e "/^diff new_file/,/^diff/ { :l1 /\ndiff/bl2 /^diff/N /^diff/bl1 :l2 s/^.*\ndiff/diff/ }" Also, I couldn't make this work using csh (it complains about unmatched "), only with the Bourne shell. Any comments? What I want is "/^diff new_file/,(/^diff/-1)d", but that ain't sed. Robert (lupton@uhccux.uhcc.hawaii.edu)