使用shell脚本从特定单词中删除剩余行

时间:2013-10-05 06:01:40

标签: shell

这是我的输出,但我只想要地址。所以我想删除到最后一行。给我一些代码删除。

  

347-6450罗伯茨街有391个链接。

     

175 E.百老汇套房208,有1个链接。

     

412 Summerhill Ave,有34个链接。

     

50 Empringham Drive有32个链接。

     

121 Willowdale Ave Suite 202,有355个链接。

     

200 Dufferin Street,有296个链接。

     

650 West Georgia Street Suite 1010,有857个链接。

     

1726 Dolphin Ave Suite 203,共有432个链接。

我想删除特定单词“with”

中的剩余行

预期产出:

  

347-6450 Roberts St

     

175 E. Broadway Suite 208

     

412 Summerhill Ave

     

50 Empringham Drive

     

121 Willowdale Ave Suite 202

     

200 Dufferin Street

     

650 West Georgia Street Suite 1010

     

1726 Dolphin Ave Suite 203

1 个答案:

答案 0 :(得分:0)

cat input.txt | sed 's/with.*$//'

sed是一个执行简单文本操作的程序。 s/with.*$//替换为字符(.*)并使用空字符串替换为行尾($)。

有关sed的更多信息,您可以阅读here