Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use output of two greps with diff

Tags:

grep

diff

How do I make better the following method of comparing certain lines (lines that start with "@") of two files? I feel certain this could be done on one line and without embarrassing temporary files. I am pretty new to Linux so go easy on me! Thanks in advance.

grep "^@" myfile1 > temp1
grep "^@" myfile2 > temp2
diff temp1 temp2
like image 733
Ben S. Avatar asked Apr 30 '13 05:04

Ben S.


1 Answers

In Bash, you can use <(...), which will handle temporaries (usually implemented as named pipes under the hood) for you:

diff <(grep "^@" myfile1) <(grep "^@" myfile2)
like image 95
Alex B Avatar answered Sep 29 '22 11:09

Alex B