LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2014, 10:59 PM   #1
robgrune
LQ Newbie
 
Registered: Apr 2014
Posts: 3

Rep: Reputation: Disabled
is "cat" command limited to only 2 files ?


I have followed all threads I could find, and read the "info cat" per terminal. All examples give a command similar to: "cat file1 file2 > mergedfile".

What I need is a way to have many input files, not 2 only. When I try this command:
"cat file1 file2 file3 file4 > mergedfile"
the merged file contains only file1 and file2: file3 and file4 are not merged.

What is the error?
Can "cat" concatenate multiple input files? how to do?
thanks!
 
Old 04-05-2014, 11:06 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,169

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
That should work - even "cat file[[:digit:]] > mergedfile" should do it. Which os/distro, and what version of cat "cat --version".
 
Old 04-05-2014, 11:06 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
Nope. the limit is the buffer size available for parameters. It tops out around 10,000 to 20,000 file names, if they are relatively short.

What error message are you getting?
 
Old 04-05-2014, 11:06 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
No, you can concatenate any number of files into stdout.

Example (from "root" because I had the "lst" files handy):
Code:
[root ~]# ls *lst
4.lst  b.lst  d.lst  f.lst  h.lst  j.lst  l.lst  n.lst  p.lst  r.lst  t.lst  v.lst  x.lst  z.lst
a.lst  c.lst  e.lst  g.lst  i.lst  k.lst  m.lst  o.lst  q.lst  s.lst  u.lst  w.lst  y.lst
[root ~]# cat *lst > test.lst
[root ~]# rm -f test.lst
 
Old 04-06-2014, 01:10 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 820

Rep: Reputation: 197Reputation: 197
Just once, try a new output file name with full path. I mean that accidentally you may be in an earlier sub-directory or reading an old version of the output.

Any ideas on how cat would work if files files3 or file4 were not text files?

OK
 
Old 04-06-2014, 03:06 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,169

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Cat couldn't care less.
 
Old 04-06-2014, 10:50 AM   #7
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Here's a script to concatenate files:

Code:
#!/bin/sh
# combines files starting with input number

base="$(echo "$@" | rev | cut -d. -f1 --complement | rev)"

ls -1 "$base".* | sort -V | while read line
do
	cat "$line" >> "$base"
done

#Xdialog --title "Finished" --msgbox "concatenation finished" 0 0

exit 0
This is for files that end in .001, .002, .003 etc.
 
Old 04-06-2014, 11:24 PM   #8
robgrune
LQ Newbie
 
Registered: Apr 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
---------- Post added 04-06-14 at 11:24 PM ----------

[/COLOR]wow, many thanks for all the replies! I have followed the above, but still no luck. My distro is Ubuntu 13.10 I receive no error messages when I attempt to cat. The input files are MTS format. Here is what I am attempting.....

1) I copy all MTS files into "/working"
2) cd /working
3) cat 001.MTS 002.MTS 003.MTS 004.MTS > merged.MTS

Always, the merged.MTS file contains the contents of the 001.MTS and 002.MTS files (which are properly concatenated). But, files 003 and 004 are simply ignored and not included in the cat process. I can find no explanation anywhere why cat would not merge all 4 files under one command.

I can, though, cat 2 files in a series.
Example:
cat 001.MTS 002.MTS > merged01.MTS
cat merged01.MTS 003.MTS > merged02.MTS
cat merged02.MTS 004.MTS > merged03.MTS

the above produces the desired result of an output file containing all 4 input files in proper cat order.
but, this is an extremely cumbersome process.

Aside, I can cat all 4 files by using "avconv", but avconv cannot preserve the MTS format (avconv must output to MP4)

interesting?

Last edited by robgrune; 04-06-2014 at 11:26 PM. Reason: error corrections
 
Old 04-07-2014, 12:09 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
How are you determining that the files weren't copied?

I do this quite frequently without a problem (usually log files).[COLOR="Silver"]

BTW, you can also use >> to append to the end of an existing file...

Last edited by jpollard; 04-07-2014 at 12:11 AM.
 
Old 04-07-2014, 12:29 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,645

Rep: Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501
what will type cat and which cat say?
Have you got any error message?
 
Old 04-07-2014, 10:56 AM   #11
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Code:
for i in 001.MTS 002.MTS 003.MTS 004.MTS
do
    cat "$i" >> merged.MTS
done
 
Old 04-11-2014, 06:04 AM   #12
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 820

Rep: Reputation: 197Reputation: 197
Quote:
Aside, I can cat all 4 files by using "avconv", but avconv cannot preserve the MTS format (avconv must output to MP4)
I think that explains it. You can't concatenate audio visual files just like that using straight `cat`. Here is the URL for the avconv documentation. As far as I can see, there is no restriction on outputting in MP4. BUT MTS seems to be a Sony format. Did you check that source?

OK
 
Old 04-11-2014, 10:23 AM   #13
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Actually you can cat mpeg and mts without any problems. More complicated containers need conversion.
 
Old 04-11-2014, 10:44 AM   #14
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,061

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
maybe they are actually avi's or something like that. people mis-label stuff all the time.
what does
Code:
file *
provide ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Why "cat" command is not executed as a separate process ? techie_san778 Linux - Server 4 10-19-2013 12:55 AM
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
LXer: Use "cat" to merge multiple files LXer Syndicated Linux News 0 07-08-2012 10:20 AM
[SOLVED] Need an explanation of here scripts as well as the "cat" command UNGR Linux - Newbie 11 08-13-2011 10:08 AM
Feeding the output of "diff" or "cat" command to dpkg --purge kushalkoolwal Debian 9 06-19-2008 07:27 AM


All times are GMT -5. The time now is 02:11 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration