From: ams AT ludd DOT luth DOT se (Martin Str|mberg) Newsgroups: comp.os.msdos.djgpp Subject: Re: Global file edit? Date: 23 Jul 1999 23:44:53 GMT Organization: University of Lulea, Sweden Message-ID: <7naupl$j1i$1@news.luth.se> References: <19990723 DOT 1942 DOT 13701snz AT roborat DOT demon DOT co DOT uk> NNTP-Posting-Host: queeg.ludd.luth.se X-Newsreader: TIN [UNIX 1.3 950824BETA PL0] Lines: 32 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Dave Scott (dave AT roborat DOT demon DOT co DOT uk) wrote: : I've just spent several hours getting to grips with sed, find and xargs, : and I realise I'm no closer to being able to do what it was I went : looking for in the first place :-\ : : Is there a simple utility available to do something like this :- : : edit : : Say for instance I wanted to replace all existing calls in a project : to malloc(), with calls to xmalloc() instead... : "edit malloc xmalloc *.c *.cpp" : which would make the changes in all the affected files, and ideally : retain the original files renamed with .bak extensions (or similar). : : The only way I can do anything like that at present is to redirect the : output of a grep into a file, and out of that manually create a batch : file (involving lots of separate calls to sed and rename). : : There must be an easier way? Perl to the rescue!!! perl -i.bak -ne 's/malloc/xmalloc/g; print' *.c *.cpp Note that this _will_ replace "xmalloc" with "xxmalloc", so don't run it twice (without moving back the .bak files). Right, MartinS