我在工作中运行 REHL7column -V
at column from util-linux 2.23.2
我有 csv 文件,其中包含一些带有长字符串的列。
我想将 csv 作为表格查看,并限制列宽,因为我
通常对抽查长字符串不感兴趣。
cat foo_bar.csv | column -s"," -t -c5
看来列宽不限于 10 个字符。
我想知道这是一个错误,还是我做错了并且看不到它?
测试输入,test.csv
co1,col2,col3,col4,col5
1,2,3,longLineOfTextThatIdoNotWantToInspectAndWouldLikeToLimit,5
运行我认为正确的命令:
cat test.csv | column -s"," -t -c5
co1 col2 col3 col4 col5
1 2 3 longLineOfTextThatIdoNotWantToInspectAndWouldLikeToLimit 5
The −c
or −−columns
选项并不像您想象的那样执行。默认情况下,column
查看所有行以找到最长的一行。如果column
可容纳 2 个
这些线的宽度为 80,然后每 2 条线适合一条:
$ cat file
1 this is a short line
2 this is a short line
3 this line needs to be 39 or less char
4 this line needs to be 39 or less char
$ column file
1 this is a short line 3 this line needs to be 39 or less char
2 this is a short line 4 this line needs to be 39 or less char
$ column -x file
1 this is a short line 2 this is a short line
3 this line needs to be 39 or less char 4 this line needs to be 39 or less char
如果你把-c
低于 80,您获得的可能性就会降低
超过 1 列:
$ column -c70 file
1 this is a short line
2 this is a short line
3 this line needs to be 39 or less char
4 this line needs to be 39 or less char
所以,简单地说,column
不能做你想做的事。 awk 可以这样做:
BEGIN {
FS = ","
}
{
for (x = 1; x <= NF; x++) {
printf "%s%s", substr($x, 1, 5), x == NF ? "\n" : "\t"
}
}
Result:
co1 col2 col3 col4 col5
1 2 3 longL 5
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)