Use pipe of commands as argument for diff

后端 未结 5 1321
傲寒
傲寒 2021-01-30 06:39

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

5条回答
  •  温柔的废话
    2021-01-30 07:26

    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)
    

提交回复
热议问题