Need help finding a file where a pattern exists and the file has a timestamp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help finding a file where a pattern exists and the file has a timestamp
# 1  
Old 03-16-2011
Need help finding a file where a pattern exists and the file has a timestamp

So, I know how to do some of this stuff on an individual level, but I'm drawing a blank as to how to put it all together.

I have a pattern that I'm looking for in a log file. The log file I know came in yesterday, so I want to limit the search to that day's listing of files. How would I do this?

I've tried using two piped greps but that doesn't seem to get me anything, obviously I'm extremely new to this.

Here's the pattern I'm using

grep <pattern I'm looking for> <filename prefix>* | grep '<Yesterday's Date>'

Thanks for any help in advance.
# 2  
Old 03-16-2011
Code:
find /path/to/logs -type f -name 'prefix*' -mtime -2 -exec grep -l 'pattern' {} \;


Last edited by jim mcnamara; 03-16-2011 at 01:41 PM..
# 3  
Old 03-16-2011
Quote:
Originally Posted by jim mcnamara
Code:
find /path/to/logs -type f -name 'prefix*' -mtime -2 -exec grep -l 'pattern' {} ;\

Is this a ksh command? I tried it and I get a prompt.
# 4  
Old 03-16-2011
Typo - my bad. See the red text above. And yes it runs in ksh.
This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 03-16-2011
Thanks that worked.

---------- Post updated at 02:20 PM ---------- Previous update was at 02:19 PM ----------

I would guess that if I wanted to look at zipped files I would replace grep with zgrep?
# 6  
Old 03-16-2011
Yes, use zgrep.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

If file pattern exists in directory then continue

he below looks in $dir for any pattern of fileone. As is, it executes but only returns File found if the exact format in the script exsists. Why isn't a pattern of fileone being looked for and if it is in $dir, File found. I think that is what should happen. Thank you :). dir=/path/to if... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Search if file exists for a file pattern stored in array

Hi experts, I have two arrays one has the file paths to be searched in , and the other has the files to be serached.For eg searchfile.dat will have abc303 xyz123 i have to search for files that could be abc303*.dat or for that matter any extension . abc303*.dat.gz The following code... (2 Replies)
Discussion started by: 100bees
2 Replies

3. UNIX for Dummies Questions & Answers

Outputting 1 file per row if pattern exists between files

I have many files that can have various amounts of rows. I essentially want to output each row into a new file if a pattern is matched between two files. I have some code that does something similar but I want it to output every single input row from every file into a separate output file; that... (5 Replies)
Discussion started by: verse123
5 Replies

4. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

5. Shell Programming and Scripting

Check for Pattern if exists write to file

Hi ! All I just want to search and write to new file if pattern is found in text file following are my text files by which I want to search Month and last column number my text file1 15-Jan-2011 25 ARTS 1255 125 125 178 198 15-Jan-2011 25 ARTS 1255 125 125 178 198 15-Jan-2011 25... (3 Replies)
Discussion started by: nex_asp
3 Replies

6. Shell Programming and Scripting

getting timestamp of a file and if it was accessed today then finding a line in it

i have my files and the variables value extracted from db is taken as in1=slot0312 in2=best in3=it is :veryliong/fine as varibles.. i have a folder stuctures in my unix machine as : /2011/hand_sl0312/best/HOD/file1.txt /2011/hand_sl0312/happy/HOD/file1.txt... (1 Reply)
Discussion started by: rajniman
1 Replies

7. Shell Programming and Scripting

Finding whether a value exists or not in a file

I am running a query against a database and spooling it to a file. I need to check to see if a certain value is in a specific field. I can use awk to check the specific field. However, part of the value changes. Part that does not change: MYPROD Right now I have OPS$MYPROD But... (4 Replies)
Discussion started by: guessingo
4 Replies

8. Shell Programming and Scripting

Grep pattern from different file and display if it exists in the required file

Hi, I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which contains rubbish information just to fill the page which is of no use. this is... (3 Replies)
Discussion started by: abinash
3 Replies

9. Shell Programming and Scripting

check if file exists with pattern matching

Hello friends, I am writing a simple shell script which will copy one particular type of files to backup folder if files exists. If files doesn't exists, mv command should not be executed. My file pattern is like wcm-spider-maestro.log.2009-07-15, wcm-spider-maestro.log.2009-07-16 etc.. I... (6 Replies)
Discussion started by: sreenu.shell
6 Replies

10. Shell Programming and Scripting

finding latest file having timestamp on it.....

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (1 Reply)
Discussion started by: kaushik25
1 Replies
Login or Register to Ask a Question