I have a tab-delimited text file which I send to column
to "pretty print" a table.
Original file:
1<TAB>blablablabla<TAB>aaaa bbb ccc
2<TAB>blabla<TAB>xxxxxx
34<TAB>okokokok<TAB>zzz yyy
Using column -s$'' -t <original file>
, I get
1 blablablabla aaaa bbb xxx
2 blabla xxxxxx
34 okokokok zzz yyy
as desired. Now I want to add colors to the columns. I tried to add the escape codes around each tab-delimited field in the original file. column
successfully prints in color, but the columns are no longer aligned. Instead, it just prints the TAB separators verbatim.
The question is: how can I get the columns aligned, but also with unique colors?
I've thought of two ways to achieve this:
- Adjust the
column
parameters to make the alignment work with color codes
- Redirect the output of column to another file, and do a search+replace on the first two whitespace-delimited fields (the first two columns are guaranteed to not contain spaces; the third column most likely will contain spaces, but no TAB characters)
Problem is, I'm not sure how to do either of those two...
For reference, here is what I'm passing to column
:
Note that the fields are indeed separated by TAB characters. I've confirmed this with od
.
edit:
There doesn't seem to be an issue with the colorization. I already have the file shown above with the color codes working. The issue is column
won't align once I send it input with escape codes. I am thinking of passing the fields without color codes to column
, then copying the exact number of spaces column
output between each field, and using that in a pretty print scheme.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…