How to Cat multiple files with numeric differences
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to Cat multiple files with numeric differences
I think this is more a of a bash-terminology question than a cat question.
I have file.mkv.001 through file.mkv.160 How do I concatenate them into file.mkv without typing every individual entry?
I think if I have file.mkv.a through file.mkv.z I can use "cat file.mkv.[a-z] > file.mkv" But that doesn't seem to work with the numeric extensions. Bash tells me "file.mkv.[001-160] not found".
Last edited by zxcvcxz; 11-19-2009 at 03:46 PM.
Reason: typo
This will get all the files you listed. It would also get others if they existed (e.g. file.mkv.199) but so long as you only have the 001 through 160 extension you mention you should be OK.
This will cat each file out in order into the file.mkv.full
Code:
for i in `ls -l file.mkv.[0-9][0-9][0-9] | awk '{print $8}' | sort -n`; do cat $i >> file.mkv.full; done
All one line. I'm not positive if the previous solution will fall in order in all versions of bourne shell... but it's definitely more elegant if its reliable.
This will cat each file out in order into the file.mkv.full
Code:
for i in `ls -l file.mkv.[0-9][0-9][0-9] | awk '{print $8}' | sort -n`; do cat $i >> file.mkv.full; done
All one line.
You wouldn't have to do the -l and awk - You could jsut do `ls file.mkv.[0-9][0-9][0-9]` but even that isn't necessary - see my post above.
Also he didn't mention a requirement that the input be sorted in order.
I did not mention that the files should be in order, but I thought the context would indicate that. "cat file.[a-z]" works in order, and .mkv is a video container file extension.
Thanks for your help, guys. What topic should I look up to understand how the square brackets work? The use we're discussing here is not the same as the left bracket command, is it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.