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?
The | command is called a pipe. It is used to pipe, or transfer, the standard output from the command on its left into the standard input of the command on its right. # First, echo "Hello World" will send Hello World to the standard output.
You can make it do so by using the pipe character '|'. Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on.
The pipe character | is used to connect the output from one command to the input of another. > is used to redirect standard output to a file.
Good news! You can use process substitution in bash:
diff <(cut -d, -f1 file1) <(cut -d, -f1 file2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With