Showing posts with label replace. Show all posts
Showing posts with label replace. Show all posts

Wednesday, May 2, 2012

[How to] Find a key word or Replace it with other string on Linux

Please refer to these examples:

Find the key word "ProcessType=6" in text files under current path (included sub folder)
> find ./ -name "*.txt" -exec grep -n -H "ProcessType=6" {} \;

Replace the key word "python2.4" with "python2.6" in python files under /opt/stack (included sub folder)
> find /opt/stack -name "*.py" -exec sed -i 's/python2.4/python2.6/' '{}' \;

Based on the script above, you will be able to find or replace a key word quickly and efficiently.