[clug] global string replacement

Kim Holburn kim.holburn at anu.edu.au
Fri Aug 15 16:38:19 EST 2003

At 4:33 PM +1000 03/8/15, Steven Hanley wrote:
>On Fri, Aug 15, 2003 at 04:23:39PM +1000, Adrian Blake wrote:
>> I need to do a global string replacement on multiple files within a
>> directory
>> e.g. replace  KPushButton with QPushButton
>> with multiple occurrences per file on all files within a directory.
>> There must be a one line command, but what is it?
>perl -i -pne 's/KPushButton/QPushButton/g' *
>-i is inplace editing, e is execute, n is line at a time input, cant
>remember p off the top of my head.

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' *

>The * is assuming you run the command from the directory you want to do it
>in and that you want to perform this on all files there.
>using perl because overkill is just enough <g>
>	See You
>	    Steve
>Men are from Earth. Women are from Earth. Deal with it.
>sjh at wibble.net http://svana.org/sjh
>You are subtle as a window pane standing in my view
>but I will wait for it to rain so that I can see you
>   Anticipate - Ani

Kim Holburn 
Network Consultant - Telecommunications Engineering
Research School of Information Sciences and Engineering
Australian National University - Ph: +61 2 61258620 M: +61 0417820641
Email: kim.holburn at anu.edu.au  - PGP Public Key on request

Life is complex - It has real and imaginary parts.
     Andrea Leistra (rec.arts.sf.written.Robert-jordan)

More information about the linux mailing list