I have an awk command which works perfectly:
awk '{a[$1]++}END{for(i in a){printf i"\t"a[i]"\n"}}' infile
It counts the number of repeats in $1. The output looks like this:
MTRFHLILLPLLFSWFSYCFG_1 1
MLAELSVAFTLAAFALA_rc_1 3
I would like to make the output red. \033[01;31m
Usually, when I want to colour the output in awk, I do it like this:
RED='\033[01;31m'
NONE='\033[0m'
awk -v r=$RED -v n=$NONE '{printf r$1n"\n"}' infile
I tried this with the command I described above (counts the number of repeats in $1), but it doesn't work. I think it is because awk is not able to recognise r and i as separate variables, for example, in bash I would use $r$i. Is this the case?
Here is the command I have tried:
awk -v r=$RED -v n=$NONE '{a[$1]++}END{for(i in a){printf ri"\t"a[i]"\n"n}}' infile
The output looks like this:
1 #See how the first half of the output (i) is missed and is not coloured.
3
Can anybody explain why this is not working and help me fix it?
Thank you