我有幾個行的文件是這樣的:修剪使用正則表達式文件/ sed的
*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.
如果'句子[n]的.'包含'WordX',刪除到行尾的? – 2013-05-08 19:05:45
是的,這是正確的。 – figos 2013-05-08 19:09:07