通过对齐给定的分隔符来表达文本

时间:2013-06-27 18:58:18

标签: text output tabular

我的问题很简单,特别是那些熟悉Vim的Tabularize插件的人。我想把我从shell中的另一个命令得到的输出列表。例如,给定以下命令产生给定的输出:

$ mpc playlist
Metallica - Ride the lightning - The call of Ktulu
Metallica - Master of puppets - Master of puppets
Metallica - Master of puppets - Orion (Instrumental)
Nirvana - Nevermind - Smells like teen spirit
Metallica - ...And justice for all - One
Metallica - ...And justice for all - ...And justice for all
Metallica - Kill'em all - Seek and destroy
Metallica - Metallica - Wherever I may roam
Metallica - Metallica - The god that failed

我需要的是一个命令,我可以将此输出传递给,并获得以下

$ mpc playlist | tabularize --delimiter=" - "
Metallica - Ride the lightning     - The call of Ktulu
Metallica - Master of puppets      - Master of puppets
Metallica - Master of puppets      - Orion (Instrumental)
Nirvana   - Nevermind              - Smells like teen spirit
Metallica - ...And justice for all - One
Metallica - ...And justice for all - ...And justice for all
Metallica - Kill'em all            - Seek and destroy
Metallica - Metallica              - Wherever I may roam
Metallica - Metallica              - The god that failed

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

您正在寻找的命令是column

尝试mpc playlist | column -t -s '-' -o '-'

遗憾的是,如果输入中有'-'个字符,并且指定' - '也将按空格排列,而不是整个字符串,则无效。

答案 1 :(得分:-1)

**匹配任何符号的一个或多个:'。*'(贪婪直到第二个连字符)
**想要模式的开始:'\ zs'(Vim语法)
**匹配的模式:' - '

 
:%Tab /.*\zs -/