【发布时间】:2017-06-26 17:43:57
【问题描述】:
我有一个短文本文件,我应该在其中使用特殊模式输出数据。我的档案:
99 test1
88 test2
10 test3
11 test1
12 test1
13 test2
14 test3
17 test1
18 test4
一个接一个,从test1到test2再到test3。所以...我已经写了命令:
sed '/test1.*\|test2.*\|test3/!d' filename
在输出中我有结果:
99 test1
88 test2
10 test3
11 test1
12 test1
13 test2
14 test3
17 test1
在这种情况下,我有一些我不需要的行:
11 test1
17 test1
这一行不是一行接一行。我怎么能做我需要的结果?请帮我。感谢您的关注。我应该得到这个结果:
99 test1
88 test2
10 test3
12 test1
13 test2
14 test3
【问题讨论】:
-
您是否注意到您的问题不清楚?
-
确定不需要这些行的标准是什么?
-
您的意思是说您需要具有完整
test{1,2,3}行序列的行并删除所有其他行吗?如果是这样:请在您的问题中添加这样的措辞,以便其他用户清楚。 -
@sorontar 很可能这就是他想要的。保持遵循模式 test1-2-3 的行。
标签: regex bash shell pattern-matching regular-language