Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use sed to replace text in subfolders

Tags:

sed

ubuntu

i use this code to replace some text in an HTML file:

sed -i 's/tttt/new-word/g' /home/zjm1126/*.html

This doesn't search for files in subfolders, though. How do I apply this command to subfolders?

like image 382
zjm1126 Avatar asked May 16 '11 10:05

zjm1126


2 Answers

find /home/zjm1126/ -name '*.html' -print0 | xargs -0 sed -i 's/tttt/new-word/g'
like image 116
sehe Avatar answered Sep 28 '22 07:09

sehe


Can you try somthing like

for z in `find /home/zjm1126/ -type f -name "*.html"`; do
sed -e 's/tttt/new-word/g' $z>temp;
done
like image 42
Rob Avatar answered Sep 28 '22 05:09

Rob