Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!mindcrf.UUCP!karish From: karish@mindcrf.UUCP (Chuck Karish) Newsgroups: comp.unix.questions Subject: Re: Patching multiple files with same text Summary: Use ex Keywords: ex sh perl awk sed Message-ID: <9003290522.AA09184@mindcrf.mindcraft.com> Date: 29 Mar 90 05:22:56 GMT References: <193@rdb1.UUCP> Sender: daemon@ucbvax.BERKELEY.EDU Organization: Mindcraft, Inc. Lines: 36 In article <193@rdb1.UUCP> root@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.