Skip to main content
added 409 characters in body
Source Link
tomocafe
  • 1.5k
  • 4
  • 20
  • 39

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' -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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

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.

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' -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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

Note that the fields are indeed separated by TAB characters. I've confirmed this with od.

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' -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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

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.

added 24 characters in body
Source Link
tomocafe
  • 1.5k
  • 4
  • 20
  • 39

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' -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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

Note that the fields are indeed separated by TAB characters. I've confirmed this with od.

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

Original file:

1<TAB>blablablabla<TAB>aaaa
2<TAB>blabla<TAB>xxxxxx
34<TAB>okokokok<TAB>zzz

Using column -s$'\t' -t <original file>, I get

1  blablablabla aaaa
2  blabla       xxxxxx
34 okokokok     zzz

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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

Note that the fields are indeed separated by TAB characters. I've confirmed this with od.

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' -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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

Note that the fields are indeed separated by TAB characters. I've confirmed this with od.

Source Link
tomocafe
  • 1.5k
  • 4
  • 20
  • 39

Color escape codes in pretty printed columns

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

Original file:

1<TAB>blablablabla<TAB>aaaa
2<TAB>blabla<TAB>xxxxxx
34<TAB>okokokok<TAB>zzz

Using column -s$'\t' -t <original file>, I get

1  blablablabla aaaa
2  blabla       xxxxxx
34 okokokok     zzz

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:

  1. Adjust the column parameters to make the alignment work with color codes
  2. 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:

Original file with color codes

Note that the fields are indeed separated by TAB characters. I've confirmed this with od.