Question

I understand that in piping a < b > c means to use the data of file b for input to program a instead of stdin, and write the output of program b to the file c instead of stdout.

What I dont understand is how to give a piping command to use the data of file b for input to program a instead of stdin and write the output of program a to the file c instead of stdout.

Where would b be a be placed in this one?

I have a < b for the stdin but dont figure a way to get the stdout.

Thanks a lot!

Was it helpful?

Solution 2

That's not actually piping, rather it's redirection of the input and output streams.

Piping is taking the standard output of one process and attaching it to the standard input of another process, such as with:

seq 1 5 | sort -r

which generates the numbers 1 through 5 (in that order) then sorts them in reverse order, as per the following transcript:

pax> seq 1 5
1
2
3
4
5

pax> seq 1 5 | sort -r
5
4
3
2
1

The sequence:

prog <infile >outfile

runs the prog program in a process and gets its standard input from the infile file and sends its standard output to the outfile file. Only one process is involved.

To "use the data of file b for input to program a instead of stdin and write the output of program a to the file c instead of stdout", you would use:

a <b >c

exactly as you have. You'll note in my examples I don't have a space between the redirection character (< or >) and the file name - I believe this makes the relationship clearer since >xyzzy means "send output to the xyzzy file".

You erroneous assertion about what a < b > c does ("to use the data of file b for input to program a instead of stdin, and write the output of program b to the file c instead of stdout") would be more apt to the separate commands:

a <b ; b >c

with no real connection between the a and b programs.

OTHER TIPS

You should do this:

a < b > c

as you mentioned in your question. This does not do what you mean it does: it does not use b as input for a and c as output for b. This uses b as input for a and c as output for a.

Your understanding is wrong.

A command such as

a <b >c

only is one command, namely a. The input to a is from file b and the output is to file c.

There is no command b (or c) being executed.

So in short, that command already does what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top