Wednesday, March 11, 2009

Shell/Bash File Combining

Ok, another post to do with Shell/Bash scripting. This time I've been playing with joining multiple files into one big file. Here's the first script:

for file in `ls dump?????0????.scr`; do cat $file >>outputfile; done

This gives me all the files that are returned from the ls command in one big file, outputfile.

The next one is a little bit more complex:

for file in `ls | grep dump00000....[0,2,4,6,8].scr`; do cat $file >>outputfile; done

This gives me all files from the ls that meet the grep command in one big file, outputfile. The grep command returns all files with an even number at the end.

Many thanks go to Phoenix^RA for helping out with these simple scripts.