命令行CSV查看器

时间:2011-05-26 00:37:31

标签: linux command-line csv cygwin

我的问题与之相同 Command line CSV viewer? 并且column -s, -t命令答案几乎是完美的 - 除了它似乎没有像我期望的那样处理空的csv字段。例如给定输入

col1,,col3
,col2,

产生

col1  col3
col2

但我想:

col1      col3
     col2

是否可以选择使用column命令或其他方法来实现上述目的? (cygwin环境)

4 个答案:

答案 0 :(得分:2)

这是优雅的最远的东西,它可能是你已经想到的并且正在寻找更好的解决方案,但我通过做一系列sed替换来在空场中放置空白来解决这个烦恼。我把这些作为我的bashrc中的函数......

csvcolumn() { sed -e "s/^$2/ $2/" -e "s/$2$/$2 /" -e "s/$2$2/$2 $2/g"  -e "s/$2$2/$2 $2/g" $1 | column -t -s$2 ; }
csvcomma() { sed -e 's/^,/ ,/' -e 's/,$/, /' -e 's/,,/, ,/g'  -e 's/,,/, ,/g' $1 | column -t -s, ; }

第一个需要两个args才能指定分隔符。第二个是相同的东西,但它只需要一个arg并假定分隔符是一个逗号,因为这通常是我使用的。

csvcolumn input.csv ,

csvcomma input.csv

答案 1 :(得分:2)

debian中存在

-n选项。 e.g:

>$ echo -e "col1,,col3\n,col2," | column -n -s, -t
col1        col3
      col2  

答案 2 :(得分:1)

使用cat and sed。

cat filename | sed 's/[~\],/\t/g'

答案 3 :(得分:0)

如果您是一名游客,请使用CSV plugin,即beautiful。{{3}}。

相关问题