Main Menu

Search

LINUX: "sed" Command to Find and Replace All Occurrences of a string inside a Directory & its Sub directories(How To Doc) ("grep" command)

Below command can be used to find and replace all occurrences of a string in files inside a directory and sub directories.

grep -rl 'string1' /tmp | xargs sed -i 's/string1/string2/g'

Above command looks for string 1 in all files inside /tmp and replaces it with string2. You can change the directory name as needed from /tmp to any directory where you want to find and replace a string.

Products to which Article Applies


All Linux Operating Systems

Additional References


https://stackoverflow.com/questions/6758963/find-and-replace-with-sed-in-directory-and-sub-directories




tarun boyella

No comments:

Post a Comment