pattern search using grep in specific range of files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers pattern search using grep in specific range of files
# 1  
Old 04-11-2011
pattern search using grep in specific range of files

Hi,

I am trying to do the following:

grep -l <pattern> <files to be searched for>

In <files to be searched for> , all files should of some specific date like "Apr 8" not all files in current directory. I just to search within files Apr 8 files so that it won't search in entire list of files.


Thanks for your suggestion..
Regards
Neeraj
# 2  
Old 04-11-2011
I dunno if i understood, but you would like to grep the content of files which have timestamp Apr 8 Smilie

If so, position yourself in folder in which you want to recursively search from e.g /myfiles.
Touch two files with range you want to search from / to
Code:
touch -t 201104042359 dateto
touch -t 201104040000 datefrom

Then you search with find and grep (-H is not avalible in all versions of grep, this is linux)
Code:
root@glitch:/myfiles# ls -lrt
total 8
-rw-r--r-- 1 root root 0 2011-02-04 22:59 nomatchfile2
-rw-r--r-- 1 root root 0 2011-04-04 00:00 datefrom
-rw-r--r-- 1 root root 7 2011-04-04 21:59 matchfile
-rw-r--r-- 1 root root 7 2011-04-04 22:59 matchfile2
-rw-r--r-- 1 root root 0 2011-04-04 23:59 dateto
-rw-r--r-- 1 root root 0 2011-06-04 22:59 nomatchfile
root@glitch:/myfiles# find $PWD -newer datefrom ! -newer dateto ! -name 'dateto' -type f  | xargs grep -H "string"
/myfiles/matchfile:string
/myfiles/matchfile2:string
root@glitch:/myfiles#

Hope that helps.
Regards.
# 3  
Old 04-12-2011
Thanks a lot... it worked after little modification... Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

awk to grab data in range then search for pattern

im using the following code to grab data, but after the data in the range im specifying has been grabbed, i want to count how many instances of a particular pattern is found? awk 'BEGIN{count=0} /parmlib.*RSP/,/seqfiles.*SSD/ {print; count++ } /103 error in ata file/ END { print count }'... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

5. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

6. Shell Programming and Scripting

How can i use grep to search a specific pattern?

Hi All, My file contain the below data : w_SA_infa1.log:INFO : LM_36620 : () Command task instance : running command , with command value . Binary file w_SA_infa1.log.bin matches w_SA_infa2.log:INFO : LM_36620 : (30377|1427806528) Command task instance : running command , with command value... (1 Reply)
Discussion started by: aliva Dash
1 Replies

7. Shell Programming and Scripting

Search for a specific data in a file based on a date range

Hi, Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application’s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and... (5 Replies)
Discussion started by: svajhala
5 Replies

8. UNIX for Dummies Questions & Answers

Coping Files for a specific date range

Hi, we have file name appended by date in yymmdd format .. ex: abc090101.dat I need to copy all the files between abc090101 to abc090331.. could you plz help me.. Thanks. (1 Reply)
Discussion started by: kolariya4u
1 Replies

9. Shell Programming and Scripting

Search files between a date range

Hi people A newbie here, thrown into the deep end. I want to select the group of files with in a range of dates and perform some operation on it. Are there inbuild date libraries i can use? I did read thru the old posts on this topic. Couldnt get much idea :(, basically want to know how I... (7 Replies)
Discussion started by: zcanji
7 Replies

10. UNIX for Dummies Questions & Answers

Search for very specific pattern with less

Hi, I want to search a certain pattern with less command in a files. For examples, I have a files with this entry: POLAR xx POLARX xc POLARXI x1 POLARZZZY vb POLARLLLLLLL ee... (1 Reply)
Discussion started by: anjas
1 Replies
Login or Register to Ask a Question