unix - Shell script traversing the all subdirectories and modifying the content of files -
i need modify number of files inside directory. need modify files contain particular text , have replace new text.
so thought of writing shell script traverse through subdirectories , modify content i'm having problem while traversing possible directories.
you can use find
traverse through subdirectories looking files , pass them on sed
search , replace text.
e.g.
find /some/directory -type f -name "*.txt" -print -exec sed -i 's/foo/bar/g' {} \;
will find txt files , replace foo bar in them.
the -i
makes sed change files in-place. can supply backup-suffix sed if want files backed before being changed.
Comments
Post a Comment