Wednesday 11 September 2013

Find and Replace a string in a file

Problem: In linux I want to find a string and replace it with other string in a file.

Solution:  Use the below command.

 
find . -type f  -print | xargs sed -i 's/abc/123/g'

The above command will recursively searches for all the files in current working directory and it replaces all the occurrences of abc with 123 in the found files.

No comments:

Post a Comment