使用* nix中的column命令格式化列表

[英]Formatting lists with the column command in *nix


I'm trying to format a list of entries in bash, and am using the column command. However, the -t option defaults to using any whitespace as a delimiter, which does not work for the data I have (it contains spaces and tabs). I can't figure out how to get the -s flag to specify a newline character as the sole column delimiter.

我正在嘗試格式化bash中的條目列表,並使用column命令。但是,-t選項默認使用任何空格作為分隔符,這對我擁有的數據(它包含空格和制表符)不起作用。我無法弄清楚如何獲取-s標志以指定換行符作為唯一的列分隔符。

2 个解决方案

#1


13  

In theory, to specify a newline, you can use the $'...' notation, which is just like '...' except that it supports C-style escape-sequences:

理論上,要指定換行符,可以使用$'...'表示法,就像'...'一樣,除了它支持C樣式的轉義序列:

column -t -s $'\n' list-of-entries.txt

However, I don't really understand the purpose of this. A newline is the row delimiter, so a column-delimiter of $'\n' is equivalent to not having any column-delimiter at all:

但是,我真的不明白這個目的。換行符是行分隔符,因此$'\ n'的列分隔符相當於根本沒有任何列分隔符:

column -t -s '' list-of-entries.txt

which means that the input will be treated as having only one column; so it's equivalent to not using column at all:

這意味着輸入將被視為只有一列;所以它相當於根本不使用列:

cat list-of-entries.txt

It seems like you actually don't want to use the -t flag, because the purpose of the -t flag is to ensure that each line of input becomes one line of output, and it doesn't sound like that's what you want. I'm guessing you want this:

看起來你實際上不想使用-t標志,因為-t標志的目的是確保每行輸入變成一行輸出,並且它聽起來不像你想要的那樣。我猜你想要這個:

column list-of-entries.txt

which will treat each line of list-of-entries.txt as a value to be put in one cell of the table that column outputs.

它將把每個list-of-entries.txt行作為一個值放在列輸出的表的一個單元格中。

#2


6  

This works to output a pretty print version of a tab delimited file

這適用於輸出制表符分隔文件的漂亮打印版本

column -t -s $'\t' list-of-entries.txt

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/08/26/724f83efbebfdfe2c9f6e80b842055ab.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com