在每个文本文件的顶部和底部添加新行 [英] Add new lines to top and bottom of every text file
本文介绍了在每个文本文件的顶部和底部添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含约2000个文本文件的文件夹。
I have a folder that contains about 2000 text files in it.
在每个文件的顶部,我需要添加这两行:
At the top of every file I need these two lines added:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
在每个文件的底部,我需要添加:
And at the bottom of each file I need this added:
</urlset>
有没有办法通过命令行对所有文件一次性执行此操作?
Is there any way to massively do this across all the files at once via command line?
提前感谢!
推荐答案
$ cat header
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
$ cat footer
</urlset>
$ cat header file footer
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
one line
</urlset>
在bash循环中包装上述内容:
To wrap the above in a bash-loop:
for f in *.xml; do cat header $f footer > tmp && mv tmp $f; done
这篇关于在每个文本文件的顶部和底部添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文