LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (http://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   egrep read file? (http://www.linuxquestions.org/questions/solaris-opensolaris-20/egrep-read-file-869708/)

type8code0 03-19-2011 11:42 PM

egrep read file?
 
Hi all,

Is it possible for egrep or zcat to read from file?

Example:-

I'm trying to find a few ip addresses in different log files. Problem is the list of ip addresses is quite big. Ip addresses that I use below are just for an example.

Code:

zcat logfile.1.Z logfile.2.Z | egrep 10.10.10.10 10.10.10.11 10.10.10.12 > output
Is it possible to do something like this?

Code:

zcat logfile.1.Z logfile.2.Z | egrep [read from file, let say “iplist”] > output
Code:

zcat logfile.1.Z logfile.2.Z | egrep [iplist] > output
Code:

cat iplist
10.10.10.10
10.10.10.11
10.10.10.12

or

Code:

zcat [read from log files, let say “logs”] | egrep [read from file, let say “iplist”] > output
Code:

zcat [logs] | egrep [iplist] > output
Code:

cat logs
logfile.1.Z
logfile.2.Z


syg00 03-20-2011 12:50 AM

Have a look at the manpage for grep - while you're at it, check out zgrep.

type8code0 03-21-2011 06:43 AM

Quote:

Originally Posted by syg00 (Post 4296703)
Have a look at the manpage for grep - while you're at it, check out zgrep.

Thanks syg00, unfortunately, zgrep is not install in the system.
Code:

SunOS{type8code0}: grep
Usage: grep -hblcnsviw pattern file . . .

SunOS{type8code0}: whereis grep
grep: /usr/bin/grep

SunOS{type8code0}: zgrep
bash: zgrep: command not found

SunOS{type8code0}: whereis zgrep
zgrep:


syg00 03-21-2011 08:05 AM

I gave a Linux answer as you posted in a Linux(sub-)forum.
A quick check shows my (old) OpenSolaris guest is broken, so I can't check the commands. Best maybe to request this thread be moved to Solaris (click on the "Report" button on your original post).

colucix 03-21-2011 10:58 AM

Moved: This thread is more suitable in Solaris/OpenSolaris and has been moved accordingly to help your thread/question get the exposure it deserves.

David the H. 03-21-2011 05:49 PM

According to this, Solaris' grep also has the -f "read patterns from file" option.

http://manpages.unixforum.co.uk/man-...-man-page.html

syg00 03-22-2011 01:23 AM

Indeed.
I managed to find a boot environment for my OpenSolaris that works. Being aimed at Linux users it has egrep that I am familiar with, but the xpg4 version does also work the same.


All times are GMT -5. The time now is 03:46 PM.