0

我的问题很简单,特别是对于那些熟悉 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

有任何想法吗?

4

2 回答 2

0

您要查找的命令是column.

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

可悲的是,如果您在输入中有字符,这将不起作用'-',并且指定' - '也将按空格而不是整个字符串进行分列。

于 2013-07-13T14:25:45.060 回答
-1

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

 
:%Tab /.*\zs -/  

 
于 2013-08-07T19:57:16.600 回答