Reputation: 264
sed 's/\<matching pattern\>/replacing pattern/g' filename
The above command is what I got from stack overflow. But this command is not working in HP-UX B.11.11 version.
Also i would like to know the answer for the below question? how to find and replace the matching pattern across all files in a directory. Repalced value should be modified/rewritten into the same file and saved.
I was able to match and replace across all files using the below command but was unable to rewrite/save the outputs into the same file.
awk 'match($0,/matching pattern/) {gsub(/matching pattern/,"replacing pattern")}1' *
Upvotes: 0
Views: 990
Reputation: 174716
You could do this through GNU find
command,
find . -type f -exec sed -i 's/match/replace/g' {} \;
It would find the files --> match the string--> replace the match --> Save the changes made to that file.
Upvotes: 1