Hello All
I am trying to grep the list of id's in a .txt file(patterns.txt) against all log files which are in /logs directory in a server.
Patterns.txt file has only ID's, that means I need to search for each and every character.
Please help me how it can be done.
There are several ways to interpret your request that would lead to wildly different suggestions.
- Please tell us what operating system and shell you're using.
- Please show us (in CODE tags) sample
patterns.txt
file contents. - Please show us (in CODE tags) sample contents of a couple of files in the
/logs
directory. - Please show us (based on the above two requests) exactly what output you're hoping to produce (in CODE tags).
- And please let us know where
patterns.txt
is located and what the name are for the files in/logs
that are to be searched. - Will you b e running this script on the server containing the
/logs
directory? If not, what is the server's name and how do you plan to access files from that server?
1.Please tell us what operating system and shell you're using.
Linux Box and i need SH script
- Please show us (in CODE tags) sample patterns.txt file contents.
patterns.txt file looks like below
67ABCD
ABC123
KJS876
ZKL789
- Please show us (in CODE tags) sample contents of a couple of files in the /logs directory.
Here is one of the sample log file, all log files has the same data format
ZKL789 is successfully processed
BKL567 is successfully processed
LKJH78 failed to execute
- Please show us (based on the above two requests) exactly what output you're hoping to produce (in CODE tags).
Since we have only 1 match, I want output to be populated in seperate output file output.txt
ZKL789 is successfully processed
- And please let us know where patterns.txt is located and what the name are for the files in /logs that are to be searched.
patterns.txt is located in directory /home/userid
I want all the files in /logs to be searched, there are 10 files in this directory and the file name in /logs directory looks like klm_debug_0107.log
- Will you b e running this script on the server containing the /logs directory? If not, what is the server's name and how do you plan to access files from that server?
Yes, I will be running on the same server
Assuming that you want the output file to be created in the /logs
directory, the following should do what you want:
cd /logs
grep -F -f /home/userid/patterns.txt *.log > output.txt
It worked, Thank you.