Text-Formatting
列–table-noextreme
--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 的列)
您的樣本數據沒有觸發 的效果
-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