【发布时间】:2014-04-15 15:04:46
【问题描述】:
我有一个格式如下的文件
file header string(s)
"section title" : [status]
unknown
text
"next section" : [different_status]
different
amount of
strings
我想把它分成几个部分,例如
file header string(s)
和
"section title" : [status]
unknown
text
和
"next section" : [different_status]
different
amount of
strings
虽然捕获该标头字符串并不重要。
如您所见,我可以依赖的拆分模式是
"string in quotes" : [string in square brackets]
这个分隔字符串也需要被捕获。
在 bash 脚本中执行此操作的简单方法是什么?我预测 awk 中的某些东西会做到这一点,但我的 awk-fu 很弱。
【问题讨论】:
-
不是“分割”空行的“模式”吗?
-
不完全。第一段之前没有空行,最后一段内有空行。小节标题后面的文字几乎可以是任何东西,所以我不能真正依赖那里的任何东西。从技术上讲,它可能类似于章节标题,但这不太可能。
-
查看
man csplit... -
我最终使用了 twalberg 对
csplit的建议,它完美而简单。