Search code examples
linuxunixhttp-redirectpiping

Multiple input text files as stdin under unix


new to Linux and C so probably a simple task..but
As per the title,

How, via the command line, do you redirect 2 distinct files as input, so that when the program is done with the first, it will move on to the second?

./a.out < in1.txt   .......

Solution

  • Probably what you are looking for is

    cat in1.txt in2.txt ... | ./a.out
    

    which will use cat to concatenate the named files to stdout, and the | (pipe) operator to take the stdout from the left and feed it into the stdin on the right.

    ./a.out > in1.txt
    

    redirects stdout, not stdin. If you want to redirect stdin, use

    ./a.out < in1.txt
    

    But you can only specify one file.

    With bash, you can also redirect from the output of a command:

    ./a.out < <(cat in1.txt in2.txt)