我有一个格式如下的文件(嗯,有点):
RECORD_SEPARATOR
foo: some foo value
bar: another value
baz: 123
RECORD_SEPARATOR
foo: another foo value
bar: yet another value
baz: 345
RECORD_SEPARATOR
foo: a third foo
RECORD_SEPARATOR
bar: a fourth bar
baz: 111
等等。这里的关键点是并非所有记录都存在所有字段。
我的问题:将这些数据转换为 CSV 格式的超级简单方法是什么?也就是说,在我的例子中
foo,bar,baz
some foo value,another value,123
another foo value,yet another value,345
a third foo,,
,a fourth bar,111
当然,您可以为此编写一个 awk(或 perl 或 Python)脚本,但我希望有一些预先存在的东西,或者一些技巧可以使它成为一个非常短的脚本。
注意:我正在寻找的东西当然是面向 Unix 命令行的。