Mail Archives: djgpp/1999/07/24/11:35:22
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 <existing_string> <replacement_string> <a_bunch_of_filespecs>
:
: 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
- Raw text -