Need help to grep every character in a file against multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to grep every character in a file against multiple files
# 1  
Old 01-07-2016
Need help to grep every character in a file against multiple files

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.
# 2  
Old 01-07-2016
There are several ways to interpret your request that would lead to wildly different suggestions.
  1. Please tell us what operating system and shell you're using.
  2. Please show us (in CODE tags) sample patterns.txt file contents.
  3. Please show us (in CODE tags) sample contents of a couple of files in the /logs directory.
  4. Please show us (based on the above two requests) exactly what output you're hoping to produce (in CODE tags).
  5. 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.
  6. 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?
# 3  
Old 01-07-2016
1.Please tell us what operating system and shell you're using.

Linux Box and i need SH script

2. Please show us (in CODE tags) sample patterns.txt file contents.

patterns.txt file looks like below
Code:
67ABCD
ABC123
KJS876
ZKL789


3. 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
Code:
ZKL789 is successfully processed
BKL567 is successfully processed
LKJH78 failed to execute

4. 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

Code:
ZKL789 is successfully processed

5. 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

6. 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

Last edited by Scrutinizer; 01-07-2016 at 04:32 PM.. Reason: code tags
# 4  
Old 01-07-2016
Assuming that you want the output file to be created in the /logs directory, the following should do what you want:
Code:
cd /logs
grep -F -f /home/userid/patterns.txt *.log > output.txt

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 01-07-2016
It worked, Thank you. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Grep a pattern from zip file which has multiple files insdie

Hi Gurus, I got a small requirement in my script to grep a specific pattern in a zip compressed file which has been created with multiple files. Sample File: 20180913.zip $> zipinfo -l 20180913.zip 20180913_file1 20180913_file2 20180913_file3 20180912_file4 20180912_file5... (1 Reply)
Discussion started by: hi.villinda
1 Replies

2. Shell Programming and Scripting

Grep strings on multiple files and output to multiple files

Hi All, I want to use egrep on multiple files and the results should be output to multiple files. I am using the below code in my shell script(working in Ksh shell). However with this code I am not attaining the desired results. #!/bin/ksh ( a="/path/file1" b="path/file2" for file in... (4 Replies)
Discussion started by: am24
4 Replies

3. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

4. Shell Programming and Scripting

Grep and replace multiple strings in a file with multiple filenames in a file

Hi, I have a file containing list of strings like i: Pink Yellow Green and I have file having list of file names in a directory j : a b c d Where j contains of a ,b,c,d are as follows a: Pink (3 Replies)
Discussion started by: madabhg
3 Replies

5. Shell Programming and Scripting

Grep multiple strings in multiple files

Hi, every one! I have a file with multiple strings. file1 ATQRGNE ASQGVKFTE ASSQYRDRGGLET SPEQGARSDE ASSRDFTDT ASSYSGGYE ASSYTRLWNTGE ASQGHNTD PSLGGGNQPQH SLDRDSYNEQF I want to grep each string in hundreds of files in the same directory, further, I want to find out the string... (7 Replies)
Discussion started by: xshang
7 Replies

6. UNIX Desktop Questions & Answers

How do you [e]grep for multiple values within multiple files?

Hi I'm sure there's a way to do this, but I ran out of caffeine/talent before getting the answer in a long winded alternate way (don't ask ;) ) The task I was trying to do was scan a directory of files and show only files that contained 3 values: I940 5433309 2181 I tried many variations... (4 Replies)
Discussion started by: callumw
4 Replies

7. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

8. Shell Programming and Scripting

Breaking a file into three new files, character by character

I am new to shell scripting, and need a script to randomly distribute each character from a file into one of three new files. I also need each character to maintain it's position from the original file in the new file (such that if a character is written to File 1, Files 2 and 3 have spaces... (10 Replies)
Discussion started by: foxcastle
10 Replies

9. UNIX for Dummies Questions & Answers

problem with grep on search string in a txt file over multiple files

I have a couple of things I got stuck on 1) I have a text file containing 25k search string that I need to search against compressed file. I have used this command but somehow it doesn't seems to use all the search terms. I have put one search string per line in the txt file (I clean up... (2 Replies)
Discussion started by: m00
2 Replies

10. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies
Login or Register to Ask a Question