Sed find and replace in folder PDF Print E-mail

Here's a handy one-liner to help you replace strings globally throughout all the files in a specified folder. This procedure is also called mass find and replace, or global replace.

You can even use it on windows if you're willing to spent a few minutes installing cygwin , a windows port of the gnu/linux most used utilities (including the bash shell and even X11)

The code below will replace every occurence of 'ugly' with 'beautiful'. 

Linux example: 

find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \;

 

Cygwin example (you have to use unix-style paths):

find /cygdrive/c/xampp/joomla/ -type f -exec sed -i 's/ugly/beautiful/g' {} \;

 

 /cygdrive/c/ stands for the root of your C windows drive letter

Also note that Cygwin requires you to use the forward slash delimiter instead of the windows backslash delimiter. The bash shell allows TAB completion for paths, just type the first few letters and hit TAB to auto-complete the path. 

If you want to filter, let's say,  php files, you can add -name '*.php' to command-line arguments, just after the search path.

find /cygdrive/c/xampp/joomla/ -type f -name '*.php' -exec sed -i 's/ugly/beautiful/g' {} \;


Add as favourites (0)

  Be first to comment this article
RSS comments

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site. Such material will be removed.
  • Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
  • Keep in mind that the above process only applies if you simply entered the wrong security code.
Name:
E-mail
Homepage
Title:
Comment:

:) :grin ;) 8) :p
:roll :eek :upset :zzz :sigh
:? :cry :( :x
Code:* Code

Powered by AkoComment Tweaked Special Edition v.1.4.2

 
Tag it:
Delicious
Furl it!
Spurl
Blinkbits
BlinkList
digg
Fark
Reddit
YahooMyWeb

Support TeachMeJoomla

Donate using PayPal
,or buy some Joomla! Books

Login Form






Lost Password?

Are you secure?

Try BitDefender antivirus scan online for free!

Satisfied?Click below to buy world's best anti virus

Buy Antivirus software

Top SE queries for this URL

sed find and replace

sed windows

find sed

sed replace

sed find

"linux find and replace"

sed search replace

cygwin find replace

sed global replace

sed replace delimiter

sed search and replace

sed global search and replace

replace

find sed replace

sed find URL

© 2008 TeachMeJoomla
Joomla! is Free Software released under the GNU/GPL License.