由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - shell problem: how to "grep" in this case?
相关主题
grep usageRe: 如何用grep查找子目录下的文件?--stop!
[转载] grep questionRe: 如何用grep查找子目录下的文件?
如何把一个目录下的文件名全部改成小写?sed? awk? or mak a program?
[转载] How to list the files with specific permission?how to grep a string in all sub-dirs?
shell programming problemshow to escape both ' and " from tcsh?
How do i get a list of all computers?where is the pre-build version of cxterm-solaris
replace a string in all files under a directory?Where's emacs' private dictionary?
How to find a file in the deep children directory?UNIX Tip: the bad and the good
相关话题的讨论汇总
话题: keyword2话题: keyword1话题: findkey1话题: grep话题: shell
进入Unix版参与讨论
1 (共1页)
r**b
发帖数: 4
1
Suppose I have a text file like this:
.
.
.
keyword1
......
keyword2
.
.
.
keyword1
......
keyword2
.
.
.
How to print lines containing "keyword1", "keyword2" and in between?
s**a
发帖数: 79
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
: .
: .
: .

t*******y
发帖数: 81
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
: .
: .
: .

1 (共1页)
进入Unix版参与讨论
相关主题
UNIX Tip: the bad and the goodshell programming problems
如何删除一组文件或给一组文件更名? How do i get a list of all computers?
regular expression中回车用什么表示?replace a string in all files under a directory?
一个高技术问题How to find a file in the deep children directory?
grep usageRe: 如何用grep查找子目录下的文件?--stop!
[转载] grep questionRe: 如何用grep查找子目录下的文件?
如何把一个目录下的文件名全部改成小写?sed? awk? or mak a program?
[转载] How to list the files with specific permission?how to grep a string in all sub-dirs?
相关话题的讨论汇总
话题: keyword2话题: keyword1话题: findkey1话题: grep话题: shell