【发布时间】:2012-11-05 20:26:12
【问题描述】:
我有一个如下所示的文本文件,我想用新字符串替换两个字符之间的旧字符串(在这种情况下是 ^ 和 |)(在这种情况下将替换为旧字符串 ^旧字符串)如果该行以特定字符串开头(在此示例中为MMX。
文本文件原件:
General start, this is a test file.
TAG okay, this line not need to be processed.
MMX ABCD ^string1|other strings abc
CCF ABCD ^string2|other strings cde, skip line
MMX CDEE ^String3|other strings aaa
MMX AAAA ^String4|other strings bbb
CCD BBBB ^String5|other strings ccc, skip line
修改后的文本文件应该是:
General start, this is a test file.
TAG okay, this line not need to be processed.
MMX ABCD ^string1^String1|other strings abc
CCF ABCD ^string2|other strings cde, skip line
MMX CDEE ^String3^String3|other strings aaa
MMX AAAA ^String4^String4|other strings bbb
CCD BBBB ^String5|other strings ccc, skip line
如何使用 shell 脚本来执行这项工作?
【问题讨论】:
标签: shell unix scripting sed awk