--table-noextreme
选项如何column
运作?
-E, --table-noextreme columns Specify columns where is possible to ignore unusually long (longer than average) cells when calculate column width. The option has impact to the width calculation and table formatting, but the printed text is not affected.
$ cat table.md
Lorem ipsum | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet
Lorem | Lorem ipsum | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | Lorem ipsum dolor
Lorem | Lorem ipsum dolor | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | Lorem
$ column -t -s '|' -o '|' < table.md
Lorem ipsum | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet
Lorem | Lorem ipsum | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | Lorem ipsum dolor
Lorem | Lorem ipsum dolor | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | Lorem
$ column -t -s '|' -o '|' --table-noextreme 3 < table.md
Lorem ipsum | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet
Lorem | Lorem ipsum | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | Lorem ipsum dolor
Lorem | Lorem ipsum dolor | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | Lorem
我怎样才能将表格格式化为
Lorem ipsum | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet
Lorem | Lorem ipsum | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | Lorem ipsum dolor
Lorem | Lorem ipsum dolor | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | Lorem
(来自 util-linux 2.37.2/arch 的专栏)
答案1
您的示例数据没有触发 的效果-E
,可能是因为第三列中的值无法确定为“异常长”。
使用此修改后的示例文本:
Lorem ipsum | Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit
Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit amet, consectetur | Lorem
Lorem | Lorem ipsum | Lorem | Lorem ipsum dolor sit
终端宽度为 80 列,我得到:
$ column -t -s \| -o \| file
Lorem ipsum | Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit
Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit amet, consectetur | Lorem
Lorem | Lorem ipsum | Lorem
(行分布在多行上)和
$ column -t -E 3 -s \| -o \| file
Lorem ipsum | Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit
Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit amet, consectetur
| | | Lorem
Lorem | Lorem ipsum | Lorem | Lorem ipsum dolor sit
但是,考虑到您的预期输出,-l
( --table-columns-limit
) 选项似乎就是您正在寻找的:
$ column -t -l 3 -s \| -o \| file
Lorem ipsum | Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit
Lorem ipsum dolor | Lorem | Lorem ipsum dolor sit amet, consectetur | Lorem
Lorem | Lorem ipsum | Lorem | Lorem ipsum dolor sit