Color escape codes in pretty printed columns

前端 未结 4 736
攒了一身酷
攒了一身酷 2020-12-18 00:39

I have a tab-delimited text file which I send to column to \"pretty print\" a table.

Original file:

1blablablabla

        
4条回答
  •  情歌与酒
    2020-12-18 01:08

    A solution using printf to format the ouput as well :

    while IFS=$'\t' read -r c1 c2 c3; do
        tput setaf 1; printf '%-10s' "$c1"
        tput setaf 2; printf '%-30s' "$c2"
        tput setaf 3; printf '%-30s' "$c3"
        tput sgr0; echo
    done < file
    

    enter image description here

提交回复
热议问题