kamashay
kamashay

Reputation: 107

How to use a text file containing list of files as input for cat Linux command?

I would like to use the cat command to concatenate multiple files located in different folders. I have a text file containing the name and location (path) of each file as a long list (e.g. filesLocationNames.txt), and would like to use it as an input for the cat command. I tried: 'cat filesLocationNames.txt | cat * > output.txt' but it didn't work.

Upvotes: 2

Views: 3821

Answers (2)

Nobody
Nobody

Reputation: 21

cat will pipe input to output, so piping the names in won't work. You need to supply the filenames as arguments to cat. E.g.:

cat `cat filesLocationNames.txt`

But that has the same problem with spaces in filenames/pathnames...

In TCSH you can try:

cat "'cat filesLocationNames.txt'"

That is doublequote (") backquote (') at the start. (No space between them!) But it will handle spaces in the names...

Also, in TCSH:

foreach FILE ( "`cat filesLocationNames.txt`" )
    echo $FILE
end

Will handle spaces in the names...


Only one catch: If filesLocationNames.txt is too long, it will exceed the line buffer and you'll need xargs. How big is it?

Upvotes: 1

Marichyasana
Marichyasana

Reputation: 3154

How about cat filesLocationNames.txt | xargs cat > output.txt

Upvotes: 2

Related Questions