|
|
Question : searching sentence and replace it in bash script
|
|
Can it be possible to write shell script that will replace same sentence in many files under some directory to my desired sentence? I know that grep can be used to search specific syntax in files under any directory. But if i want to replace anyhting is there any ready command available on redhat linux systems?
|
Answer : searching sentence and replace it in bash script
|
|
Perl or sed are great for this. Depending on your type/version of sed, you can edit in place. Perl can also edit in place this way:
perl -pi.bak -we's/some string to search for/replace with this/;' your-file.txt
or for many files:
find /some/directory -name 'your-file-wildcard.*' | xargs perl -pi.bak -we's/some string to search for/replace with this/;'
Or sed (some versions):
sed -i.bak 's/some string to search for/replace with this/' your-file.txt
Note that the s/// takes a regular expression (like egrep) for the first argument.
|
|
|
|