18 Sep Search and replace a word in multiple files from command line in linux, mac
For search and replace words in many files using command line and using ack:
Open Terminal Console :
For search only:
1 | ack -a 'border-radiused' |
For search and list only the files where contain words:
1 | ack -a -l 'border-radiused' |
Y now we search the word border-radiused and we will replace instead borderradiused in the current directory in all the files where contain that word with next command:
1 | ack -a -l 'border-radiused' | xargs sed -i '' -e 's/border-radiused/borderradiused/g' |
After to run the before command if we search again the word
1 | ack -a 'border-radiused' |
Using silver searcher
1 | ag "stub_paperclip_processing\(CuratedBook\)" --nogroup | awk '{print substr($1,1,index($1,":")-1);}' | xargs sed -i '' -e "s/CuratedBook/BookImage/" |
Listing the files that contain a specific string
1 | ag "stub_paperclip_processing\(CuratedGame\)" --nogroup | awk '{print substr($1,1,index($1,":")-1);}' |
We can see that any file contain the word
And that’s it, see you
No Comments