3

I wanted to list all functions in 2 files I have, so I used:

cat <file_A> | grep -E "^function"
cat <file_B> | grep -E "^function"

How can I compare the outputs and highlight the similarities?

3

Two options here:

  • if you need GUI solution - then you can use Meld Merge tool:

    sudo apt install meld
    
    meld <(grep -E "^function" file_A) <(grep -E "^function" file_B)
    
  • if you need terminal solution - use power of diff:

    diff <(grep -E "^function" file_A) <(grep -E "^function" file_B)
    
  • no way of doing so without saving output to files? – CIsForCookies Dec 9 '18 at 13:10
3

You can use the process substitution functionality in this way:

diff <(cat <file_A> | grep -E "^function") <(cat <file_B> | grep -E "^function") 

You do not need to use cat in this case. Also, there is a nice wrapper of diff called colordiff (it must be installed: sudo apt install colordiff). Here is one of my favorite usages:

colordiff --side-by-side --left-column --width=180 --show-C-function <(grep -E "^function" <file_A>) <(grep -E "^function" <file_B>) 

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.