我有一个包含几行这样的文件:
*wordX*-Sentence1.;Sentence2.;Sentence3.;Sentence4.
这些句子之一可能包含也可能不包含 wordX。我想要的是修剪文件使其看起来像这样:
*wordX*-Sentence1.;Sentence2.
其中 Sentence3 是第一个包含 wordX 的地方。
我怎样才能用 sed/awk 做到这一点?
编辑:
这是一个示例文件:
*WordA*-This sentence does not contain what i want.%Neither does this one.;Not here either.;Not here.;Here is WordA.;But not here.
*WordB*-WordA here.;WordB here, time to delete everything.;Including this sentece.
*WordC*-WordA, WordB. %Sample sentence one.;Sample Sentence 2.;Sample sentence 3.;Sample sentence 4.;WordC.;Discard this.
这是所需的输出:
*WordA*-This sentence does not contain what i want.%Neither does this one.;Not here either.;Not here.
*WordB*-WordA here.
*WordC*-WordA, WordB. %Sample sentence one.;Sample Sentence 2.;Sample sentence 3.;Sample sentence 4.