searching for a string in directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers searching for a string in directory
# 1  
Old 09-27-2002
searching for a string in directory

Hi,

I have a directory with a couple of thousand logs in it. The log files are created every 5 minutes. I want to search these logs grep for a specific sting and more importantly print the name of the files where that sting was found.

e.g.

all logs begin om20020927

what I have been doing is

cat OM20020927* |grep 'BalDeductError 6'

That returns the instance of the string, but nt the files that is is found in.

Any help greatly apreciated.

W
# 2  
Old 09-27-2002
Tools Use grep only

You can use grep only

>> grep 'BalDeductError 6' OM20020927*

Now it will show the filename infront of each string found
# 3  
Old 09-27-2002
cd to the directory with your logs in & do this

find . -name "om20020927*" -print | xargs grep "'BalDeductError 6'" > grep.log

grep.log will then contain a list of all matches in your logs which contain "om20020927"
# 4  
Old 09-27-2002
If you re-read man about util grep,
you type something like this:


[def]$ grep "BalDeductError 6" om20020927*


Smilie

--
Sincerely,
Andrew A.Romanchenko
AlarIT programmer
http://www.AlarIT.com
# 5  
Old 09-27-2002
Check your man page. Some versions of grep allow you to specify the "-l" flag to only printer the file name... See if you have that.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Searching the file in a directory

Hi Folks, I am using the putty as I need to check the logs, My query is that I know the location of my logs ..that is cd /var /logs/abc.log so I can reach to this place and open the logs in putty, But what About if I do not the location only thing I know the name of the abc.log , and I have... (1 Reply)
Discussion started by: KAREENA18
1 Replies

2. Shell Programming and Scripting

searching the required string and appending string to it.

Hi all, I have some data in the form of adc|nvhs|nahssn|njadnk|nkfds in the above data i need to write a script so thet it will append "|||" to the third occurnace in the string ..... the outout should look like adc|nvhs|nahssn||||njadnk|nkfds Thanks, Firestar. (6 Replies)
Discussion started by: firestar
6 Replies

3. Shell Programming and Scripting

Searching directory

The command is to search all the matched directory under $HOME, the input i directory is the last argument it works perfectly by itself but after a method call, it wont work cant figure out why dirNameCheck(){ for i in $* do test $1 done noMatch=`find HOME -type d -name $i |... (0 Replies)
Discussion started by: cryogen
0 Replies

4. Solaris

Searching for files in a Directory

Hi, I am trying to write a script that will search in a particular directory and tell me how many files are in there. I then want to be able to email certain users of how many files are in that directory and what the file names are? any help would be great as i am getting confused. thanks (3 Replies)
Discussion started by: Pablo_beezo
3 Replies

5. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

6. Shell Programming and Scripting

Searching directory tree

I'm currently trying to write a script that will do the following: search a given directory tree for a file with MMDDYYYY in the name. delete those files only. I can't figure out how to make the script delete the files with the MMDDYYYY in the filename after finding them. Should I export... (7 Replies)
Discussion started by: blane
7 Replies

7. UNIX for Dummies Questions & Answers

Searching directory for file that contains some text.

If I go into a directory and type in .. more * | grep foo I get the lines of text that contain foo in all of the files in the directory out of all of the files that are there. How do I make it so I can find out what the names of the files are that contain that text "foo"? By doing what I... (4 Replies)
Discussion started by: LordJezo
4 Replies

8. Shell Programming and Scripting

Searching for directory

Hi, I am new to Unix and am using csh to create a script where all files in a directory of a particular type are changed. As an example, if rename.csh tmp .tab .txt is entered at the command line, all of the .tab files in the tmp directory will be changed to .txt files. I have created the... (8 Replies)
Discussion started by: Enigma23
8 Replies

9. Filesystems, Disks and Memory

Searching for a pattern in a Directory

How to search a given pattern in the files which are present in my current working directory and its subdirectories recursively (1 Reply)
Discussion started by: gandhevinod
1 Replies

10. Shell Programming and Scripting

directory searching

i have a set of directories, all with a set of files inside ie name/week1 there is a selection of files in each directory, and i need to read each one, and find data in each one, although not all the numbers are there can anyone help me please (i know this is kinda vague, just pm... (2 Replies)
Discussion started by: st00pid_llama
2 Replies
Login or Register to Ask a Question