Andrew Latham
Andrew Latham

Reputation: 6132

Pipe two different outputs into a command that takes two inputs

It seems like this should be pretty easy but it's not intuitive to me how to do it. I have two files and I want to diff their first columns (this is an example, I'm sure there are other ways to do this). So I might do cut -d, -f1 file1 > tmp1, cut -d, -f1 file2 > tmp2 and then diff tmp1 tmp2. But I want to do it without using the tmp files.

An example of the sort of thing I'm expecting would be ((cut -d, -f1 file1), (cut -d, -f1 file2)) > diff but this is not real code.

Is there a way to do this?

Upvotes: 9

Views: 2364

Answers (2)

csiu
csiu

Reputation: 3269

Another way to do this is:

cut -d, -f1 file1 | diff - <(cut -d, -f1 file2)

Upvotes: 2

hek2mgl
hek2mgl

Reputation: 157927

Good news! You can use process substitution in bash:

diff <(cut -d, -f1 file1) <(cut -d, -f1 file2)

Upvotes: 13

Related Questions