PDA

View Full Version : Colour in awk



Mbengi Bongi
November 18th, 2008, 11:13 AM
Can someone advise me on how to make the output of an awk statement a different colour?

My statement is:


awk -v KEY=/$input/ 'BEGIN { FS = "," } KEY { print "Name: " $2 }' data1.csv

The statement retrieves data from a csv file, what I want is the value $2 a different colour from Name:

Any help would be appreciated :)

geirha
November 18th, 2008, 11:36 AM
No hits on "colo(u)r" in the man-page, so I guess the only way is with ansi escapes.

{ print "Name: \033[1;31m" $2 "\033[0m" }

http://en.wikipedia.org/wiki/ANSI_escape_code

Mbengi Bongi
November 19th, 2008, 12:02 AM
That's perfect Geirha, that works a treat!

I did try ANSI escape codesd before but I got the quotes in the wrong place! :oops:

Thank you very much ):P

masuch
September 12th, 2011, 09:16 PM
thanks , that's exactly what i needed