Skip to content

Instantly share code, notes, and snippets.

@djamol
Created July 14, 2020 05:46
Show Gist options
  • Save djamol/ddf40a89f5fbc97a8b6350f96347e9e7 to your computer and use it in GitHub Desktop.
Save djamol/ddf40a89f5fbc97a8b6350f96347e9e7 to your computer and use it in GitHub Desktop.
cd /home/directoy; grep -nr 'yourString*'
grep -r --include=.txt 'searchterm' ./ ...or case-insensitive version... grep -r -i --include=.txt 'searchterm' ./ // /home/directory location directory, find string,word yourString* (* means after yourString any thing word character) ---Find And Replace String or word cd /home/directoy; grep -rl FindString | xargs sed -i 's/FindString/ReplaceString/g'
example: find google.in string and replace with yahoo.com cd /home/directoy; grep -rl google.in | xargs sed -i 's/google.in/yahoo.com/g'
grep -rl --include=.php campaign12 | xargs sed -i 's/campaign12/campaign1/g'
grep -rl --include=\*.php campaign12 | xargs sed -i 's/campaign12/campaign1/g'
If you have list of files you can use
replace "old_string" "new_string" -- file_name1 file_name2 file_name3
If you have all files you can use
replace "old_string" "new_string" -- *
If you have list of files with extension, you can use
replace "old_string" "new_string" -- *.extension
#scan only extension files and replace whole line .line start with "ErrorDocument 401" all txt file only in /home folder and sub folder
find /home/ -type f -name '*.txt' -readable -writable -exec sed -i "/^ErrorDocument 401/c\ " {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment