What does this shell script do? for file in *.htm *.html ; do sed ‘s/strong/STRO
ID: 3634648 • Letter: W
Question
What does this shell script do?for file in *.htm *.html ; do
sed ‘s/strong/STRONG/g
s/img src/IMG SRC/g’ $file > $$
mv $$ $file
done
Explanation / Answer
Dear, for file in *.htm *.html ; do sed ‘s/strong/STRONG/g s/img src/IMG SRC/g’ $file > mv $file done In the above code, “for file in *.htm *.html” Will loop through all files such *.htm and *.html. “do” The set of instructions to be performed will be given after this statement. “sed ‘s/strong/STRONG/g s/img src/IMG SRC/g’ “ Here “sed” (Stream Editor) is a unix command to edit the content of a stream. “s/” is used for substitution, “strong/” is the word to be substituted, “STRONG/” with this word substitution is done, “/g” is for global substitution. So this statement will substitute all occurrences of “strong” with “STRONG” in the file. s/img src/IMG SRC/g’ Here also the command will substitute all occurrences of “img src” with “IMG SRC” in the file. “$file” is used as a shell variable. It will bring all the files one by one while iterating. “ > mv $file done” will renames the new files with the same name and repeats until all files are edited. Hope this would help you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.