[clug] global string replacement

Matthew Hawkins matt at mh.dropbear.id.au
Fri Aug 15 17:10:22 EST 2003

Kim Holburn said:
> You only need p.  n is go through the file 1 line at a time.  p is go
> through the file a line at a time and print after executing any
> commands.
> perl -pi -e 's/KPushButton/QPushButton/g' *

... and while we're editing each others one-liners, don't forget to
account for the fact there may be more files in that directory than will
fit on your shells command line, so instead of that asterisk at the end,
do something like this:
find . -print0 | xargs -0 perl -pi -e 's/KPushButton/QPushButton/g'

(which also works around the possibility that some filenames are screwed)

Also remember to anchor your regexps, there are some times you really
don't want to replace *every* occurrance.. just every one that's a
function call, or at the beginning or end of a line, etc.  And anchored
regexp's usually run faster too :)

More information about the linux mailing list