Use pipe of commands as argument for diff

后端 未结 5 1361
傲寒
傲寒 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

    Try process substitution:

    $ diff file <(grep -E "^[0-9]+$" file)
    

    From the bash manpage:

    Process Substitution

    Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of <(list) or >(list). The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.

提交回复
热议问题