1

This question actually asks the 'inverse' solution as the one here, namely I would like to wrap the long column (column 4) on multiple lines. In effect, the output should look like:

cat test.csv | column -s"," -t -c5 

col1 col2  col3  col4                col5
1    2     3     longLineOfText      5
                 ThatIWantTo
                 InspectAndWould
                 LikeToWrap

(excuse the u.u.o.c. duplicated over here :) )


The solution would ideally :

  • make use of standard *nix text processing utilities (e.g. column, paste, pr which usually are present on any modern Linux machine nowadays, usually coming from the core-utils package);
  • avoid jq as it is not necessarily present on every (production) system;
  • don't overheat the brain: yes... am looking mainly at you awk & co. gurus :). "Normal" awk / perl / sed is fine.
  • as a special bonus , a solution using vim would be even more welcome (again, no brain smoke please), since that would allow for syntax-coloring as well.

The background: I want to be able to make sense of the output of docker history, so as a last resort even some Go Template-magic would suit, as would using jq.

In extreme cases (if the benefits of ease-of-remembering-and-use outweigh the inconvenience of downloading a new utilty (preferably self-contained / static linked) utility on the server - is ok, or using json processing commands (in which case using pythons json module would be preferred)

Thanks !

LE: Please keep in mind, that dockers output has the columns separated with several spaces, which unfortunately confuses most commands :(

cg79
  • 63
  • 5
  • What did you try? – romainl Apr 20 '22 at 18:50
  • Did you try the `-W` option? E.g. `cat test.csv | column -s"," -t -W4 -c40` – pmf Apr 20 '22 at 18:53
  • @romainl: Tried `docker history image | column -t -W4` with various options for the separator, but `column` always gets confused at the separator which is a sequence of spaces in docker-s output. seems. @pmf: Thanks, but it doesn't _cut_ it :) since also by looking at manual page, seems that `-c` option is not specific to a column, but to entire output, isn't it ? – cg79 Apr 20 '22 at 19:01
  • Several solutions are offered at https://stackoverflow.com/questions/56778612/how-to-wrap-lines-within-columns-in-linux – peak Apr 20 '22 at 21:04
  • @peak: yes, but all use awk / perl , are complex & hard to remember, are actually more like programs than one-liners, unfortunately – cg79 Apr 21 '22 at 10:38
  • @cg79 what's wrong with storing those scripts under `~/bin` and calling them? You don't need to remember them, you only need to give them a short name. – knittl Sep 05 '22 at 19:30

0 Answers0