Bash command to write the contents of multiple files into a single file

你说的曾经没有我的故事 提交于 2019-12-11 05:07:02

问题


I'm wondering what's the best way to combine multiple .html files (spread across many folders) into one single html file. If someone could create a simple bash command that would be fantastic. (This is a workaround so I can use firebug's command line API to effectively search an entire site for html selector combinations. As far as I know, firebug can only search on one page.)

Any help is greatly appreciated for this stymied front-end designer.


回答1:


cat file1.html file2.html file3.html > newfile.html

Edit This may be easier

find . -name="*.html" | xargs cat >> ../newfile.html

Note that newfile.html is pushed up from the current directory so it is not cat'ed into itself.




回答2:


Well, if you're not concerned about the resulting file being correct, cat seems like the easiest way to go:

cat file1.html file2.html file3.html > result.html

But of course each of those files with have an <html> tag at the top and a closing one at the bottom, so it won't be a valid HTML file. Firefox will probably load it, but I don't know how it will display it... perhaps only the first one?




回答3:


You cold always use grep to search something in a group of files instead of merging all of the files and then searching that one file.

grep <string you are looking for> <folder containing all of files> -r



回答4:


for file in `ls *.html`; do cat "$file" >> output.html; done


来源:https://stackoverflow.com/questions/640363/bash-command-to-write-the-contents-of-multiple-files-into-a-single-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!