1,105,340 Community Members

grep lines that contain three words from files in the same directory

Member Avatar
erezz
Newbie Poster
10 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I need to grep lines that contain three words from files in the same directory
And next to the greped line I need to have the file that the line came from.
Example:
The directory is:
/var/logs
The files in the directory are:
XSLog2012.05.14-15.40.48.txt
XSLog2012.05.14-15.49.01.txt
XSLog2012.05.14-15.57.11.txt
XSLog2012.05.14-16.05.07.txt
XSLog2012.05.14-16.11.41.txt
XSLog2012.05.14-16.18.26.txt
XSLog2012.05.14-16.25.16.txt
XSLog2012.05.14-16.32.00.txt
XSLog2012.05.14-16.38.43.txt
XSLog2012.05.14-16.45.41.txt
XSLog2012.05.14-16.52.50.txt
XSLog2012.05.14-17.00.03.txt
XSLog2012.05.14-17.06.38.txt
XSLog2012.05.14-17.14.00.txt
XSLog2012.05.14-17.20.41.txt
XSLog2012.05.14-17.27.35.txt
XSLog2012.05.14-17.34.57.txt
XSLog2012.05.14-17.42.23.txt
XSLog2012.05.14-17.50.01.txt
XSLog2012.05.14-17.57.01.txt
XSLog2012.05.14-18.04.16.txt
XSLog2012.05.14-18.12.12.txt
XSLog2012.05.14-18.19.54.txt
XSLog2012.05.14-18.26.49.txt

The words that I need to be greped in one line are:

YYYY
2@0011234abc12
EEE

The output should look like this:

XSLog2012.05.13-21.54.41.txt:YYYY 792 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.13-22.14.28.txt:YYYY 797 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.13-22.39.20.txt:YYYY 802 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.13-23.08.40.txt:YYYY 807 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.13-23.29.07.txt:YYYY 812 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.13-23.54.00.txt:YYYY 817 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.14-00.29.26.txt:YYYY 822 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0
XSLog2012.05.14-01.22.47.txt:YYYY 827 bbln/2@0011234abc12.abc.abc.abc.aa XXXX 1.0 EEE 1.0

Thanks in advence.

Member Avatar
rubberman
Senior Poster
3,989 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 500 [?]
Skill Endorsements: 87 [?]
 
0
 

Try reading the man page for grep/egrep: man grep

Member Avatar
erezz
Newbie Poster
10 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Solved,
Thanks.

Question Answered as of 1 Year Ago by rubberman
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article