[How To] – Linux command grep & sed for find & replace


As a solution provider, I always need to setup a new website/system to our client.
It is painful on old application that have multiple setting files need to be modify (Example: database connection setting).
Luckily, a simple and powerful Linux command can save my time.

Below is the grep and sed command in Linux that can find and replace the content in files.


View Code LINUX
//grep -lir '<KEYWORD>' . --exclude=*.svn-base | xargs sed -i 's/<KEYWORD>/<NEW_SETTING>/g'
grep -lir 'database1' . --exclude=*.svn-base | xargs sed -i 's/database1/database2/g'

Leave a Reply