I have such issue. In one script I have a formatted printf string. Some columns should be marked in different colors, but if try to mark the with colors it destroy whole formatting.
This one is don't work
printf "%5s|%-6.5s|%-70.69s|%-9.8s|%7.6s|%7.6s|%-15.30s\n" \ "Nr. " " One " "Two" "Three" "Four" ""$(tput setaf 1)"Five"$(tput sgr0)"" " Six" Without colors works:
printf "%5s|%-6.5s|%-70.69s|%-9.8s|%7.6s|%7.6s|%-15.30s\n" \ "Nr. " " One " "Two" "Three" "Four" "Five" " Six" Has anybody a solution?
Thanks in advance!
%7.6sis clipping it to only 6 characters; the color codes are normally 5 characters (each), so you get the opening color code and one character of printable content. Either put the color codes in the format string as @oguzismail suggested), or put them in separate fields with no length limit. BTW, your quoting on the color-coded argument is also weird.printfconsists of a format string and an argument list which printed according to the format. You should see colours as part of the format-string and hence, they should belong in the format string.