我怎样才能格式化bash命令的整齐的列输出 [英] How can I format the output of a bash command in neat columns
问题描述
我有输出的多行信息,我想在列格式化的功能。问题是数据的任何特定的细胞(如果我可以用这个词)的宽度是可变的,所以管道为类似awk并没有给我我想要的东西。
I have a function which outputs many rows of information which I want to format in columns. The problem is that the width of any particular "cell" (if I may use that term) of data is variable, so piping it to something like awk does not give me what I want.
功能是钥匙(这不是问题),我想是这样的:
The function is "keys" (not that it matters) and I'm trying something like this:
$ keys | awk '{ print $1"\t\t" $2 }'
但输出(它的一个片段,那是)是这样的:
but the output (a snippet of it, that is) looks like this:
"option-y" yank-pop
"option-z" execute-last-named-cmd
"option-|" vi-goto-column
"option-~" _bash_complete-word
"option-control-?" backward-kill-word
"control-_" undo
"control-?" backward-delete-char
我怎么能强迫的东西留在整齐的列?这是可能使用awk,或者我需要用别的东西吗?
How can I force things to stay in neat columns? Is this possible with awk, or do I need to use something else?
推荐答案
列(1)
是你的朋友。
column(1)
is your friend.
$ column -t <<< '"option-y" yank-pop
> "option-z" execute-last-named-cmd
> "option-|" vi-goto-column
> "option-~" _bash_complete-word
> "option-control-?" backward-kill-word
> "control-_" undo
> "control-?" backward-delete-char
> '
"option-y" yank-pop
"option-z" execute-last-named-cmd
"option-|" vi-goto-column
"option-~" _bash_complete-word
"option-control-?" backward-kill-word
"control-_" undo
"control-?" backward-delete-char
这篇关于我怎样才能格式化bash命令的整齐的列输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!