I am trying to find duplicates on a disk containing all my pictures. for this purpose I created a file containing potential duplicates (using some exif and check sum properties but this is not the purpose of the question).

I have created a file using this format (using exiftool mainly and little formatting):

./PICTURES_archives/a organiser/Ipad/823WGTMA/IMG_1777.JPG <--> ./PICTURES_archives/a organiser/Ipad/965YOKDJ/IMG_2346.JPG

./PICTURES_archives/a organiser/iCloud Photos/My Photo Stream/IMG_0954.JPG <--> ./Pictures A classer/Iphone 5S Icloud/IMG_0954.JPG

I created the following awk script to show the same output in a different format:

awk -F'<-->' 'BEGIN {
                format1= "%25s %-50s\n"; 
                format2 = "%-50s %s\n";
                if (longa>longb) long=longa; 
                for(i=1; i<=long;i++) {
                    if(a[i]==b[i]) printf format1,"    ",  a[i] ; 
                    else printf format2, a[i],b[i]
                print "\n"
              }' identical.txt 

More readable to me. the output is :

file a common path file b
. .
a organiser
IMG_1777.JPG IMG_2346.JPG
. .
PICTURES_archives Pictures A classer
a organiser Iphone 5S Icloud
iCloud Photos IMG_0954.JPG
My Photo Stream

QUESTION : I would like to put color for the output when the information for file a and b are different.

I tried to end the function with

printf format2, "\033[33m"a[i] "\033[0m","\033[33m"b[i] "\033[0m"

but it shows me the following output

ESC[33m823WGTMAESC[0m                                  ESC[33m965YOKDJESC[0m
ESC[33mIMG_1777.JPG ESC[0m                             ESC[33mIMG_2346.JPGESC[0m

the ESC[33m is not interpreted as color.

Any tips?

OS: Darwin macOS Big Sur

  • 5
    Exactly what shows you the output? Those colour codes only work on the terminal (and they vary by terminal type) -- redirecting to a file will contain the octal data itself. Where does "ESC" come from as a 3-letter string? Commands like od show ascii values in a spaced-out format -- I don't know anything that would render precisely "ESC[". Jul 12, 2021 at 11:57
  • 1
    What are you actually trying to do? i.e. what is the original problem you're trying to solve that made you decide that file format with <--> as the separator was a good way to do it? This looks like an XY Problem to me.
    – cas
    Jul 12, 2021 at 12:51
  • @Paul_Pedant that's how less will show them if you don't use -R. Try printf "\033[33m foo \033[0m\n" | \less. Ajo, is that what you are using? Does using less -R solve it for you or do you need more?
    – terdon
    Jul 12, 2021 at 12:55
  • Please edit your question to provided minimal, complete, concise, testable, plain text sample input and expected output that demonstrates your problem and which we can copy/paste to test a potential solution against so we can help you.
    – Ed Morton
    Jul 12, 2021 at 13:17
  • If you're just trying to color some awk output then see stackoverflow.com/a/64046525/1745001 for one way to produce output with foreground and/or background coloring.
    – Ed Morton
    Jul 12, 2021 at 13:20

1 Answer 1


The problem was that I was piping the output to less and less doesn't interpret these escape sequences by default. However, it works fine if I use less -R. This is documented in man less:

       -R or --RAW-CONTROL-CHARS
              Like -r, but only ANSI "color" escape sequences and OSC  8  hy‐
              perlink  sequences  are  output  in "raw" form.  Unlike -r, the
              screen appearance is maintained correctly, provided that  there
              are  no  escape sequences in the file other than these types of
              escape sequences.  Color escape sequences  are  only  supported
              when  the  color  is changed within one line, not across lines.
              In other words, the beginning of each line  is  assumed  to  be
              normal  (non-colored),  regardless  of  any escape sequences in
              previous lines.  For the purpose of keeping track of screen ap‐
              pearance,  these  escape  sequences are assumed to not move the
  • Thanks for posting an answer! Since it was based on my comment, I took the liberty of removing your kind attribution and adding some context and the relevant section of the man page to flesh it out a little.
    – terdon
    Jul 12, 2021 at 21:46
  • Thank you. Nicely done. I will be able to close the subject in few hours.
    – Ajo
    Jul 13, 2021 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .