问题
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