Some sed work would do the trick:
a
sedto remove ANSI color codessed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"a
sedto replace space(s) with tabssed -r "s/\s+/\t/g"
Finaly:
printf "\033[0;32;1mgreen_apple\033[0m 1 100
orange 20 19
pineapple 1000 87
avocado 4 30" \
| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" \
| sed -r "s/\s+/\t/g"
Output:
green_apple 1 100
orange 20 19
pineapple 1000 87
avocado 4 30
PS: I honestly tested all this with ls --color output. This is easier than playing with echo.
About removing ANSI color codes:
- From UL: Program to strip color codes
- From SO: Removing color codes with bashRemoving color codes with bash
- another source about removing color codes