目前我正在使用带有 grep 查找/替换的 TextWrangler (mac),但也很乐意使用任何其他编辑器或命令行工具。
我有一个结构如下的文本文件(是的,每行开头都有一个空格):
Reference 1 - This is a sentence with a period. And this exclaims! So does this one!
Reference 2 - This questions? And this, this one responds. But this YELLS!
而且我需要保留参考,但将每个句子分成自己的行,如下所示:
Reference 1 - This is a sentence with a period.
Reference 1 - And this exclaims!
Reference 1 - So does this one!
Reference 2 - This questions?
Reference 2 - And this, this one responds.
Reference 2 - But this YELLS!
我可以让它保留参考和最后一句话(复制/替换了那里的换行符,这就是为什么最后的中断 - 否则它与文档的其余部分匹配):
^([^-]+ -\s+)(?:([^.!?]+?[.!?]))(([^.!?]+?[.!?])+?)$
替换是这样的:
\1\2
\1\3
结果如下所示:
Reference 1 - This is a sentence.
Reference 1 - And this exclaims! So does this one!
Reference 2 - This questions?
Reference 2 - And this, this one responds. But this YELLS!
如果我多次运行它,它不会将其他两个句子分成新行。但是如果我在替换中添加另一行:
\1\4
然后我得到这个结果:
Reference 1 - This is a sentence.
Reference 1 - And this exclaims! So does this one!
Reference 1 - So does this one!
Reference 2 - This questions?
Reference 2 - And this, this one responds. But this YELLS!
Reference 2 - But this YELLS!
我希望这很简单,我只是缺少一个开关/修饰符/等。
如果我一次只能做一句话,我不介意做其他清洁工作。
有任何想法吗?