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.

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

Solved,
Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.