LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   is "cat" command limited to only 2 files ? (https://www.linuxquestions.org/questions/linux-newbie-8/is-cat-command-limited-to-only-2-files-4175500724/)

robgrune 04-05-2014 10:59 PM

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!

syg00 04-05-2014 11:06 PM

That should work - even "cat file[[:digit:]] > mergedfile" should do it. Which os/distro, and what version of cat "cat --version".

jpollard 04-05-2014 11:06 PM

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?

PTrenholme 04-05-2014 11:06 PM

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


AnanthaP 04-06-2014 01:10 AM

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

syg00 04-06-2014 03:06 AM

Cat couldn't care less.

metaschima 04-06-2014 10:50 AM

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.

robgrune 04-06-2014 11:24 PM

---------- 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?

jpollard 04-07-2014 12:09 AM

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

pan64 04-07-2014 12:29 AM

what will type cat and which cat say?
Have you got any error message?

metaschima 04-07-2014 10:56 AM

Code:

for i in 001.MTS 002.MTS 003.MTS 004.MTS
do
    cat "$i" >> merged.MTS
done


AnanthaP 04-11-2014 06:04 AM

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

metaschima 04-11-2014 10:23 AM

Actually you can cat mpeg and mts without any problems. More complicated containers need conversion.

schneidz 04-11-2014 10:44 AM

maybe they are actually avi's or something like that. people mis-label stuff all the time.
what does
Code:

file *
provide ?


All times are GMT -5. The time now is 06:49 PM.