LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to Cat multiple files with numeric differences (https://www.linuxquestions.org/questions/linux-software-2/how-to-cat-multiple-files-with-numeric-differences-770292/)

zxcvcxz 11-19-2009 03:14 PM

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".

MensaWater 11-19-2009 03:29 PM

cat file.mkv.[01][0-9][0-9] >file.mkv

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.

rweaver 11-19-2009 03:29 PM

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.

MensaWater 11-19-2009 03:32 PM

Quote:

Originally Posted by rweaver (Post 3763133)
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.

zxcvcxz 11-19-2009 03:45 PM

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?

MensaWater 11-19-2009 03:59 PM

Regular Expresions (a/k/a regexp)

ghostdog74 11-19-2009 06:38 PM

Code:

cat file.mkv.{001..160}

zxcvcxz 11-19-2009 06:49 PM

Well thanks ya'll, the regular expression only method even returns the list in numeric order on my system.


All times are GMT -5. The time now is 04:37 AM.