awk -F: '{ printf "%-3s %-2s","\n" $1 $2; }'
How do i add in color code? '\e[1;32m'
I try adding in to printf, it give me output of the string instead of color code..
'\e[1;32m' .......
Try this example:
echo "line 1
line 2" | awk '/line/ {print "\033[32m" $1 "\033[31m" $2 }'
Color is given by "\033[32m"
For Colors:
30 - black 34 - blue
31 - red 35 - magenta
32 - green 36 - cyan
33 - yellow 37 - white
\033[?m
properly quoted gives colour:
awk 'BEGIN{ print "\033[34msomething in colour\033[0m";}'
notice how one needs to unescape $1
below:
echo something | awk '{ print "\033[34m"$1" in colour \033[0m";}'
awk
doesn't recognize '\e' as a code for the escape character. Here's a workaround (something more elegant may exist):
# Decimal 27 is the ASCII codepoint for the escape character
awk '{ printf "%c[1;32m foo\n", 27 }' <<<foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With