Highlight 'comm' command output

Given the output below (simplified) extracted from the comparison of two curl -I commands saved in two different files, I am looking for the best approach to highlight the following scenarios in a script:

  1. this header exists only in file1.txt but this one does not
  2. this one exists in both cases but the values are different

I was thinking about assigning green color to column 3, orange color if the header is found both in column 1 and column 2 and no color if the header is found only either in column 1 or column 2...
I am also open to suggestions different from colors and by processing file1.txt and file2.txt with other options than comm command.

root# comm <(sort file1.txt | tr '.' ',') <(sort file2.txt | tr '.' ',')

Accept-Ranges: none
Cache-Control: private, max-age=0
    Cache-Control: public, max-age=14400
    CF-Cache-Status: HIT
        HTTP/1,1 200 OK

Hi.

Off the top of my head -- possible approaches, neither tested:

1) cut the fields into 3 files, add appropriate color to each line, paste modified files back together,

2) use spc with appropriate Regular Expressions to color each one of the 3 fields:
Supercat

NAME
       spc - colorize and print to standard output

SYNOPSIS
       spc [OPTION] [-c file|-C directory] [-t type] [FILE]...

DESCRIPTION
       Colorize  specific  patterns in the input and write to standard output.
       The output may optionally be formatted as a web page.
...

Best wishes ... cheers, drl

2 Likes