I am having trouble with this simple task:
cat file | grep -E ^[0-9]+$ > file_grep diff file file_grep
Problem is, I want to do this without file_grep
I have tried:
diff file `cat file | grep -E ^[0-9]+$`
and
diff file "`cat file | grep -E ^[0-9]+$`"
and a few other combinations :-) but I can't get it to work. I always get an error, when the diff
gets extra argument which is content of file filtered by grep
.
Something similar always worked for me, when I wanted to echo
command outputs from within a script like this (using backtick escapes):
echo `ls`
Thanks
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.
In this case, the output of the process and command substitution provided by parallel is being used as arguments to the cp command. We use the tokens “::::” and “:::” since parallel uses what is on the right as a file-argument and argument respectively.
One of the most powerful shell operators is the pipe ( | ). The pipe takes output from one command and uses it as input for another.
The Linux diff command is used to compare two files line by line and display the difference between them. This command-line utility lists changes you need to apply to make the files identical.
If you're using bash:
diff file <(grep -E '^[0-9]+$' file)
The <(COMMAND)
sequence expands to the name of a pseudo-file (such as /dev/fd/63
) from which you can read the output of the command.
But for this particular case, ruakh's solution is simpler. It takes advantage of the fact that -
as an argument to diff
causes it to read its standard input. The <(COMMAND)
syntax becomes more useful when both arguments to diff
are command output, such as:
diff <(this_command) <(that_command)
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