I need some help with ksh command

jersiq

Senior member
May 18, 2005
887
1
0
Basically I have ~25 gz files that I need to search for certain text.
Say my first criteria is xx, and the second is yy

I have gzegrep available, but I can't seem to find anything on the web that allows me to basically use an "and" for the expressions. What may be complicating matters is that xx and yy are on different lines. However, I know the patten of the text (yy is 5 lines below xx)

Is this even possible?

I tried using egrep on a file with the same text values that is not zipped, just to get the format correct as gzegrep invokes egrep

egrep "(33336|751)" /file
I learned this is "or" not and

egrep -e 33336 -e 751 /file
same result as the "or" above
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
You have not explained yourself very well. Do you want to find lines that contain both xx and yy? Lines that contain xx or yy? Lines that contain xx only if the line below contains yy?

Does your example with egrep actually do what you want? If so, why can you not use it with gzegrep?

Do you have zcat available? That is sometimes helpful as you can just pipe the plain text into grep or egrep although it looks like gzegrep is supposed to have that built in (I'm not familiar with it myself).
 

jersiq

Senior member
May 18, 2005
887
1
0
Sorry for the poor wording.

Basically we have text files that contain errors or printouts from the system of a period of a day. The way the output is printed in my case, it is in a block of four or five contiguous lines.

I want to search for all the lines that have 33336 in the second line and ALSO have 751 in the sixth line. I'd rather not gunzip the files as that would take a lot of disk space as the files are rather large.

On an uncompressed file I could normally use cgrep -T 33336 /file and then manually look for the sections that contain 715.

Sorry about the vagueness also, but my company frowns on us talking about the exact equipment that I am working on.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
How about:
$ zcat /file | cgrep -T 33336

That'll allow you to use cgrep on uncompressed text without it ever hitting the disk.