Tuesday, February 8, 2011

Excellent Unix Commands for finding and replacing in vi and file system

If you want to find something

$ find . | xargs grep "string"

It will find all the files recursively and then display the strings


vi commands (advanced)

Go to / Replace functionality can be used in vi... like this

:%s/stringtobereplaced/stringwithwhichtoreplace/g

(Esc + colen (:) + percentage (%) s /string1/string2/g

for eg:

:%s/avggstdh/avggstrh/g

will replace all the occurences of avggstdh with avggstrh.

No comments: