Sample Header Ad - 728x90

A shell tool to “tablify” input data containing ANSI escape codes

7 votes
5 answers
1448 views
I have input containing ANSI color codes that I'd like to tablify. I want the output to remain colored, so the tablified output should maintain the ANSI color codes. Hence, naively stripping them away does not meet my requirements. For example, for this input, \033[0;32;1mgreen_apple\033[0m 1 100 orange 20 19 pineapple 1000 87 avocado 4 30 The output I expect would be similar to green_apple 1 100 orange 20 19 pineapple 1000 87 avocado 4 30 In the above output, "green_apple" should be colored according to the color codes from the input i.e. green. I'd like to know how this can be accomplished. I've tried column, but it doesn't handle ANSI codes. The output of echo '\033[0;32;1mgreen_apple\033[0m 1 100 orange 20 19 pineapple 1000 87 avocado 4 30' | column -t is unfortunately green_apple 1 100 orange 20 19 pineapple 1000 87 avocado 4 30 Notice the non-tablification.
Asked by Jimmy Dean (81 rep)
Mar 24, 2014, 07:56 AM
Last activity: Feb 19, 2024, 06:25 PM