开发者

Grep and inserting a string

开发者 https://www.devze.com 2023-02-24 08:36 出处:网络
I have a text file with a bunch of file paths such as - 开发者_如何学Cweb/index.erb web/contact.erb

I have a text file with a bunch of file paths such as -

开发者_如何学Cweb/index.erb

web/contact.erb

...

etc. I need to append before the

</head>

a line of code, to every single file, I'm trying to figure out how to do this without opening each file of course. I've heard sed, but I've never used it before..was hoping there would be a grep command maybe?

Thanks


xargs can be used to apply sed (or any other command) to each filename or argument in a list. So combining that with Rom1's answer gives:

xargs sed -i 's/<\/html>/myline\n<\/html>/g' < fileslist.txt


while read f ; do
    sed -i '/<\/head>/i*iamthelineofcode*' "$f"
done <iamthefileoffiles.list

or

sed -i '/<\/head>/i*iamthelineofcode*' $(cat iamthefileoffiles.list)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号