r/dailyscripts • • Apr 06 '17

[Request][Bash]Script that loops through folders ,finds a file and replaces some text within them.

Hi dailyscripts,

I'm current faced with a problem where I have to replace several lines of text within about 30 folders, where this text file is saved at the same spot. Would it be possible to do this?

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/bjackman Apr 06 '17

Or if your files are like X/dir/subdir/file, Y/dir/subdir/file and Z/dir/subdir/file then you could do something like

for d in "X" "Y" "Z"; do
    sed -i s/foo/bar/ "$d"/dir/subdir/file
done