Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi good people of this community,

Say I have a script called script, that reads from stdin and spits out some results to the screen.

If I wanted to feed it contents of one file, I would have typed:

$ ./script < file1.txt

But what if I want to feed the contents of the multiple files to the script the same way, is it at all possible? The best I came up with so far was:

cat file1.txt file2.txt > combined.txt && ./script < combined.txt

Which uses two commands and creates a temp file. Is there a way to do the same thing but bypassing creating the combined file?

share|improve this question
up vote 9 down vote accepted

You can use cat and a pipe:

cat file1 file2 file3 ... fileN | ./script

Your example, using a pipe, and no temp file:

join file1.txt file2.txt | ./script
share|improve this answer
D'oh. It is so simple I am not even sure how I did not realize it myself. Thanks! – Nikita Sep 8 '11 at 1:12
Useful use of cat award! – glenn jackman Sep 8 '11 at 1:58
@Bruce Ediger: I assume you were just pointing out a way to use join without a temp file, but just to make it clear to the reader: cat f1 f2 does not produce the same output as join f1 f2 – Peter.O Sep 8 '11 at 3:04
@fred thanks for pointing this out -- I used join in my example because I was playing with it before; in reality, for my example I was using cat. – Nikita Sep 8 '11 at 12:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.