• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Easiest way to search thru files and replace various strings


I need to replace various strings in certain files that can be located in various subdirectories and levels underneath a main directory. I am way rusty with my shell and sed, so was looking here for some help. I would attempt this with sed but if there is an easier that would be great.

My script currently processes each directory and performs some other tasks. I now need to add a line or two that will search and replace these strings I am referring to.

Thx,
CC
0
rhugga
Asked:
rhugga
1 Solution
 
chris_calabreseCommented:
Yes, sed is the way to go here.

Something like this:

umask 077
...
sed 's|original text|replacement text|g' < "$file" > "$file.tmp" \
&& cp "$file.tmp" "$file"
rm -f "$file.tmp"
0
 
rhuggaAuthor Commented:
Thanks,

Didn't realize it would be that simple, heh.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now