Reputation: 49
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 beer
string is not always there in one of the files or existed but in a different name like apple:0
Upvotes: 2
Views: 291
Reputation: 5424
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
Upvotes: 4