Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep for multiple things in multiple files

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
There are a lot of like lines in some files that we have here and I'm trying grep out some lines with certain criteria. The criteria I'm trying to grep for is the number 217848 and BIG. How do I grep for these both in the same command?
 
Give the following a try:
Code:
egrep &quot;217848|BIG&quot; <file list>
 
Actually,the above will grep for 217848 OR &quot;BIG&quot;,not both.

The correct way would be:

grep &quot;217848&quot; <file list> |grep BIG


&quot;Long live king Moshiach !&quot;
 
Hi jalge

If u want to display all lines that contain the pattern
such as 217848 and BIG
Please issue the command as follows

#grep -E &quot;217848|BIG&quot; <file_name>

I think this is what u need...

sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
# fgrep &quot;217848&quot; <file list> |grep BIG

should be better for more than one file
 
If you want to get all instances of lines that have &quot;217848&quot; and &quot;BIG&quot; in the files, you have to use

grep -E &quot;217848|BIG&quot; <filename or list of files>
or
egrep &quot;217848|BIG&quot; <filename or list of files>

Using grep &quot;217848&quot; <file or list of files> | grep BIG, or grep &quot;217848&quot; <file list> |grep BIG will only give you one return, even if there are many lines that have both &quot;217848&quot; and BIG in them.

 
Hi,

If &quot;217848&quot; and &quot;BIG&quot; should be in the same line - then use:
grep &quot;217848&quot; <file list> |grep BIG
This gives the &quot;AND&quot; effect.

If &quot;217848&quot; and &quot;BIG&quot; should be in the differnt lines and you want to gerp for either one - then use:
grep -E &quot;217848|BIG&quot; <filename or list of files>

This gives the &quot;OR&quot; effect.




&quot;Long live king Moshiach !&quot;
 
Or you could use the v simple

awk '/BIG/ && /217848/' filenames

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top