Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Wednesday, February 11, 2009

Find and Replace using find and sed command

This is the best command line I have ever found to search and replace text into files within directories, sub directories.

Command:

find searching_dir -name .dir_name_to_prune -prune -o -exec sed -i 's/Searched Text/Replacing Text /g' {} \;

Example:
find . -name .svn -prune -o -exec sed -i 's/Powered by: /Site Developed by /g' {} \;
Description:
find : the find command
. : current directory (you can set other)
name : name the file list
svn : the svn dir will be prouned
prune : used to prune dirs/files
o : options
exec : executind sed command
sed : the sed command
i : this will insert new text while searched text matches
's/ : this will search for finding matches
/g' : make the operation globally.
{} \; : Out put and termanating the command line


Thats all, this works nice.....