Sed find and replace in folder |
| Saturday, 23 February 2008 | ||||
|
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 letterAlso 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' {} ; Related articles(beta):
Thanks for the info, Hi, If you're having trouble trying to replace strings that contain slashes or backslashes, you can always use pipe '|' as a string delimiter Write Comment |
||||
| Last Updated ( Thursday, 18 September 2008 ) | ||||
Joomla stuff
Newsletter
Auto tags
sed replace
sed find and replace
find sed
sed find
sed search and replace
sed find replace
sed search replace
find replace sed
sed global replace
find exec sed
linux sed replace
find and replace sed
Sed global search and replace
find and sed
sed search and replace example
find and replace with sed
find sed replace
linux sed search and replace
sed replace line
search replace sed
sed folder
search and replace sed








