Patching multiple files with same text

Chuck Karish karish at mindcrf.UUCP
Thu Mar 29 15:22:56 AEST 1990


In article <193 at rdb1.UUCP> root at rdb1.UUCP (Robert Barrell) writes:
>     In a case where several files may have a given group of text lines, and
>that group of lines must be replaced in all files by another group of lines,
>is there any way to use patch, sed, or awk (sorry, I don't have perl) to
>perform such a patch?  The problems I am encountering are:

When I have to do this, I write a shell script that runs ex on each
of the files.  'pattern1' and 'pattern2' delimit the text to be removed;
'newtext' is the name of a file containing the replacement text.
'newtext' cound easily be entered inline in the script.  ed is faster
than ex if its file size limitation (~128 K) doesn't cause problems.

 *-*-*-*

for file in $*
do

	echo "
$file"
	cp $file $file.new
	ex $file.new << EOF
	1
	/pattern1/,/pattern2/d
	-
	r newtext
	w
	q
EOF

	diff $file $file.new

done

 *-*-*-*

If the diffs look OK, move each $file.new to $file.



More information about the Comp.unix.questions mailing list