how to run a script on subfolder file in a folder
i have a folder 'root' with .html files in it. Want to run a script which should search and replace a string in all these .html files. this script should search these .htmls as well as any other .html file in subfolders of 'root'. So script should also search sub-folder of root folder.
|
find 'root' -type f -iname "*.html" -print | while read file; do sed -i 's/regexp/replacement/g' "$file"; done
Yves. |
Or a slightly shorter version:-
Code:
find 'root' -type f -iname "*.html" -exec sed -i 's/regexp/replacement/g' '{}' \; |
thnx...dear..it helped
rgds. sumit |
Quote:
|
Quote:
Code:
find 'root' -type f -iname "*.html" -exec sed -i 's/regexp/replacement/g' '{}' \; 'root' - The path of the diretory you weant to start searching in, e.g. /home/centinul -type f - Find regular files. -iname "*.html" - Do a case insensitive search to match <anything>.html -exec - execute the following, up to the \;, once for each result of the search, replacing '{}' with the file name. sed - The name of a command to edit text -i - Do the editing in place, not to the console or another file. 's/regexp/replacement/g' - 'do a search and replace / look for text that matches this regular expression / replace it with this text / do it globally, dont stop at the first match' |
All times are GMT -5. The time now is 10:12 PM. |