【发布时间】:2016-08-26 02:33:34
【问题描述】:
我想使用 shell 脚本将字符串第一次出现和文件中最后一次出现之间的数据写入另一个文件。
我尝试使用以下 sed 命令打印字符串匹配所在的行。
sed -n '/Air/p' ashu.txt
示例:ashu.txt 包含
I am a good student
Air is polluted
water is not free
now Expensive Air will be
上面的 sed 命令给出如下输出
Air is polluted
now Expensive Air will be
但我想要如下所示。
Air is polluted
water is not free
now Expensive Air
请容忍我在帖子中的文字对齐方式。
【问题讨论】:
-
如果
Air只出现一次怎么办? -
然后它应该打印包含单词“Air”的那一行