Redian新闻
>
shell problem: how to "grep" in this case?
avatar
shell problem: how to "grep" in this case?# Unix - 噫吁兮,危乎高哉
r*b
1
Suppose I have a text file like this:
.
.
.
keyword1
......
keyword2
.
.
.
keyword1
......
keyword2
.
.
.
How to print lines containing "keyword1", "keyword2" and in between?
avatar
s*a
2
You need to write your own script to do this. Any script language...you must
know one I assume.
sd

【在 r**b 的大作中提到】
: Suppose I have a text file like this:
: .
: .
: .
: keyword1
: ......
: keyword2
: .
: .
: .

avatar
t*y
3
awk 'BEGIN{findkey1=0;}
{if ($0 ~ /keyword1/){findkey1=1;}
if(findkey1=1){print;}
if($0 ~ /keyword2/){findkey1=0;}
}' input-file
it should all be on the same line.
not sure about the actual syntax since I don't have
a reference book at hand, but you get the idea.

【在 r**b 的大作中提到】
: Suppose I have a text file like this:
: .
: .
: .
: keyword1
: ......
: keyword2
: .
: .
: .

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。