Finding/Grep on files with date and hour in the file name


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Finding/Grep on files with date and hour in the file name
# 1  
Old 06-13-2012
Question Finding/Grep on files with date and hour in the file name

Hi,
I have a folder structure as follows,
Code:
DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt
                   -> 01 -> ABC_2012-01-03_01.txt
                   -> 02 -> ABC_2012-01-03_02.txt
                   ...
                   -> 23 -> ABC_2012-01-03_02.txt
     -> 2012-01-02
     -> 2012-01-03
     ....

So the dir DATA contains the above hierarchy,
User input Start and End Data
I want to grep on all those files between the input datesSmilie, I want a list of files which come under the input dates.
note that the files creation or modified date is not the date and hour contained in the file name so cannot use find newer/modified command.
So what could be the easiest way of doing it, After finding the files i want to grep a string "PQRS" on the selected files for the input dates.
Any help on this would be highly appreciated...!!! TIA


Moderator's Comments:
Mod Comment Duplicate thread: Continues here:

https://www.unix.com/shell-programmin...file-name.html

Last edited by methyl; 06-13-2012 at 09:54 AM.. Reason: duplicate
# 2  
Old 06-13-2012
find

Hi,
Try this one,
Code:
cd DATA
find . -name "*' | awk '/^\.\/2012-01-0[1-9]/{print;}'|xargs -I '{}' grep -l 'PQRS' {}

here i am listing all the files from jan 01-09 and then grepping for pattern, if found just displays the file name..
Cheers,
Ranga:-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep in a log file within a time range (hour)

Hi, im trying to write a grep script that returns me the last inputs added in the last hour in the log file. Literally i have nothing yet but: grep 'Line im looking for' LOGFILE.log | tail -1 this only gives me the last input, but no necessarily from the last hour. Help Please. (4 Replies)
Discussion started by: blacksteel1988
4 Replies

2. Shell Programming and Scripting

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 -> 2012-01-03 So the dir DATA contains the above hierarchy, User input Start and... (6 Replies)
Discussion started by: mihirvora16
6 Replies

3. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

4. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

5. Shell Programming and Scripting

finding the files based on date..

Hi to every one , i had ascenario like this.. i had path like export/home/pmutv/test/ in this i will recive 43 files daily with each file having that days date i.e like product.sh.20110512 like this i will 43 files every day i had to find the files. if files are avaliable i... (2 Replies)
Discussion started by: apple2685
2 Replies

6. Shell Programming and Scripting

Finding files for a date

Hi, I have a directory with files from past 2 years.I need to find all the files for a specific date . Due to certain reasons I could not use this command in my process find . -type f \( -newer /tmp/May-1-2007 -a ! -newer... (4 Replies)
Discussion started by: Raamc
4 Replies

7. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

8. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

9. Shell Programming and Scripting

Get date and time for past 1 hour from current date

Hi, I need to get the date and time for past 1 hour from the current date. Anyone know how to do so? Thanks (5 Replies)
Discussion started by: spch2o
5 Replies

10. Shell Programming and Scripting

Finding mail per hour

Hi, i have a logfile of a mail server it looks like this: d k 1004210238.380677500 1004210238.454490500 1004210238.679567500 3621 <VOLENDAM@Malawi.com> local.EDAM@Frankrijk.com 6053 81 I have got the following script to set the time in normal gmt time and to filter de failed messages, but i... (2 Replies)
Discussion started by: Prince2
2 Replies
Login or Register to Ask a Question