LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 11-19-2009, 03:14 PM   #1
zxcvcxz
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
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
 
Old 11-19-2009, 03:29 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 11-19-2009, 03:29 PM   #3
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
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.

Last edited by rweaver; 11-19-2009 at 03:33 PM.
 
Old 11-19-2009, 03:32 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by rweaver View Post
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.
 
Old 11-19-2009, 03:45 PM   #5
zxcvcxz
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
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?

Last edited by zxcvcxz; 11-19-2009 at 03:47 PM.
 
Old 11-19-2009, 03:59 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Regular Expresions (a/k/a regexp)
 
Old 11-19-2009, 06:38 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
cat file.mkv.{001..160}
 
Old 11-19-2009, 06:49 PM   #8
zxcvcxz
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Well thanks ya'll, the regular expression only method even returns the list in numeric order on my system.
 
  


Reply

Tags
bash, cat



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[rsync] get the differences between the source files and the existing files djgerbavore Linux - Networking 2 06-04-2008 12:05 PM
Using cat for ISO files jmsvbit Linux - Newbie 2 01-04-2007 04:35 PM
differences between files alaios Linux - General 2 11-15-2004 09:34 AM
Differences between files? kryptobs2000 Linux - Software 1 06-22-2004 04:28 PM
cat - joining files u02gtt Linux - Newbie 6 04-22-2002 08:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration