Sed -- deleting to line BEFORE regexp match

Robert Lupton lupton at uhccux.uhcc.hawaii.edu
Mon Feb 20 08:54:21 AEST 1989


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 at uhccux.uhcc.hawaii.edu)



More information about the Comp.unix.questions mailing list