2

I have two files that will always hold different strings, I want to know a way to print out everything in those two files and highlight only the differences between them.

$cat file1.txt
fox:1
bike:3
beer:21

$cat file2.txt
fox:1
beer:22
bike:3

$pr -m -t file1.txt file2.txt
fox:1                         fox:1
beer:21                       bike:3
bike:3                        beer:22

I want beer:21 beer:22 to be highlighted in red. keep in mind that beerstring is not always there in one of the files or existed but in a different name like apple:0

Noor
  • 49
  • 6

1 Answers1

4

You can use diff and set color for changed lines:

diff --old-group-format=$'\e[0;31m%<\e[0m' 
     --new-group-format=$'\e[0;31m%>\e[0m'      
     --unchanged-group-format=$'\e[0;32m%=\e[0m'    file1 file2
Farvardin
  • 5,336
  • 5
  • 33
  • 54
  • I tried that, but can I make it side by side? Because the -y doesn’t work with this, do you know to? – Noor May 23 '18 at 07:51