Cat all files in a directory, with a specific file at the beginning an end...?

Posted by Aeisor on Ask Ubuntu See other posts from Ask Ubuntu or by Aeisor
Published on 2012-11-29T22:25:42Z Indexed on 2012/11/29 23:19 UTC
Read the original article Hit count: 191

Filed under:

Is there a way to cat all files in a given directory, but with a particular file at the beginning and end?

For example, say I have: file1.js, file2.js, file3.js, file4.js, file5.js -- Effectively I would like to cat file2.js file*.js file3.js > /var/www/output.js

I've tried a few variations of these

find ! -name "file2.js" ! -name "file3.js" -type f -exec cat file2.js {} file3.js > /var/www/js/output.js \;
find ! -name "file2.js" ! -name "file3.js" -type f | xargs -I files cat file2.js files file3.js > /var/www/output.js

but the best I can get out of it is file2.js added before and file3.js added after all other files (multiple times)

I know I could specify the files in the order I wanted manually, but this is not maintainable (I'm expecting, potentially >100 files).

I have looked through man cat, as well as a handful of websites devoted to xargs, find and cat to no avail.

Thanks in advance.

© Ask Ubuntu or respective owner

Related posts about find