我有一个格式为“foo=”是第一个” foo1=“是第二个” foo3=“是第三个”的字符串以及许多类似于上述模式的字段。我想解析这个并将 o/p 作为
foo foo1 foo3
is a first one is a second one is a third one
非常感谢任何帮助。
最佳答案
对输出进行列化是困难的部分。 (我同意 Noufal 的观点,即 perl 是一个很好的方法。)但是,使用其他更基本的工具也是可行的。例如:
$ cat input foo is a first one foo1 is a second one foo3 is a third one $ ( awk 'NR % 2' input; awk 'NR % 2 == 0' input ) | paste - - - | column -s' ' -t foo foo1 foo3 is a first one is a second one is a third one
(请注意,列的 -s 参数应在单引号之间包含一个制表符。)
关于shell - 想要在shell脚本中解析一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5786393/