I have many .html files and I need to add a meta tag after <head>'s start tag in each file.
How I can do that?
vimsuited for the task?
vim, you can do:
:%s/<head\b[^>]*>/& <meta foo="bar">/g
You could also do this in GNU
sed, which would possibly be more fitting:
for file in *.html; do sed -i 's/<head\b[^>]*>/& <meta foo="bar">/g' "$file" done
-i breaks symlinks.
sed -i '/PATTERN/ a\ Line which you want to append' filename
for this example
sed -i '/<HEAD>/a <meta>' test.txt <HEAD> <HEAD>
<HEAD> <meta> </HEAD>
The above command will append new line after the string get matched. However this will give wrong result if file has input string as
<HEAD><TITLE></TITLE> <meta> </HEAD> //which is wrong.
May be we can try this approach:
sed -i 's/<HEAD>/<HEAD><meta>/' filename