tags:

views:

761

answers:

4

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.

+5  A: 
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.

grieve
+4  A: 

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?

rmeador
This does not easily get all the files in the sub-directories.
grieve
+1  A: 
for file in `ls *.html`; do cat "$file" >> output.html; done
Judge Maygarden
Watch out for spaces in file names! I would read the files into an array first, and then iterate over them in a for loop, or maybe use 'while read line; do'
guns
True, but you go to hell for using spaces in file names. ;)
Judge Maygarden
+2  A: 

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
nan
I think the -r has to come before the string and the folder.
grieve
grep -r <string> <folder> for example "grep -r milquetoast ."
grieve
I thought so at first as well, but it also works at the end; I just did a quick check.
nan