how to filter file for specific date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to filter file for specific date
# 1  
Old 08-02-2012
Bug how to filter file for specific date

Hi

My OS is solaris 64 bit 10, I have many files in a logs directory where we recive 40-50 logs every day. i have last 20 days file present in this directory. I want to move each day file to a particulaar directory whose name is appended with the date of file.

eg



Code:
1.txt file date 31-jul-20122.txt file date 31-jul-20123.txt file date 01-Aug-2012
then create a directory for old files of 31-jul RIO_31-Jul-2012 and move them and like wise for 01-aug files.

I have written a scripts which is running fine for current date but i don't know how t modify it to accomdate old date.

My scripts is as below

Code:
NEWDIR=RIO_31-Jul-2012
 mkdir /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/$NEWDIR
 cd /var/opt/ers/logs/rio
 touch -t `date +%Y%m%d0000` dummy
 find . -newer dummy -type f  |
 while read fname
 do
     mv $fname /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/$NEWDIR
 done

Can you please help me to list all the file of 27-Jul-2012, how can i achive it


Thanks


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-02-2012 at 06:20 AM.. Reason: code tags
# 2  
Old 08-02-2012
You should put " around $fname in case you ever get a file with a space in the name (imagine the chaos if you accidentally create a file in that dir that starts with a space character).

As for your question, check out the -mtime and +mtime arguments to find. It's not as fine control as using -newer like you are, but if you only need days, not hours or minutes, then it will do the job for you.

Failing that, create two dummy files, much the way you created your "newer" one above, then ls -t1 to sort by date and go through the files until you hit the first of your dummy files, then start processing, and stop when you reach the second one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. UNIX for Beginners Questions & Answers

Help with Grep Specific Date From One File Into A New One

Hello All, First post, don't know much about Linux/Unix, but I need some help. Normally, I do grep 'what I'm searching for' FILE > file.txt so I can pull data from one file, and put it into a new one. The issue I am having is with specific dates, since the date field is 4, and it appears... (3 Replies)
Discussion started by: DennisG34
3 Replies

3. Shell Programming and Scripting

How to print the specific part of the file name with file creation date?

Hello Folks, I have an requirement, where i need to get total count of the file based on creation date with there filename selected pattern. Filename: MobileProtocol.20171228T154200.157115.udr I want to get the count of files created on each day based on a pattern find. find . -type... (7 Replies)
Discussion started by: sadique.manzar
7 Replies

4. Linux

Filter log file contents between date

Hi, Could you please provide me command to filter contents between date in a log file? Say for example, in a log file I want to capture contents between date May 01 from 5am to 9 am. OS -- Linux Regards, Maddy (1 Reply)
Discussion started by: Maddy123
1 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

Need help in a script to filter specific pattern

Hello , Below is the command srvctl config database -d cmdbut -s boms10.world Below is the output. Now in the command instead of cmdbut it will be a variable like $database which would be called in the script as below: srvctl config database -d $database -s $service Now,as shown in... (6 Replies)
Discussion started by: Vishal_dba
6 Replies

7. Shell Programming and Scripting

Delete file with specific date

let say i have list of file PermissionsDirectoriesGroupSizeDateDirectory or file drwx------2users4096Nov 2 19:51mailv drwxr-s---35www 32768Jan 20 22:39public_htmlt drwx------ 2 users 4096 Nov 2 19:51 mail drwxr-s--- 35 www 32768 Jan 20 22:39 public_html drwxr-s--- 35 www 32768 Jan... (3 Replies)
Discussion started by: Jewel
3 Replies

8. Shell Programming and Scripting

find command to filter specific type of files older than certain date.

Hi I need to find the list of files in a directory and to do some specific operations based on the type of files. suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months. i used the below query but the... (2 Replies)
Discussion started by: msathees
2 Replies

9. Shell Programming and Scripting

Filter date and time form a file using sed command

I want to filter out the date and time from this line in a file. How to do this using sed command. on Tue Apr 19 00:48:29 2011 (12 Replies)
Discussion started by: vineet.dhingra
12 Replies

10. UNIX for Dummies Questions & Answers

how do I filter for a specific line in a file?

It seems like it should be very simple to have a command like grep return a specific line from a file but I can't find anything in the man pages to make grep search by line. I've looked in cat as well. Anyone know how to return a single line from a file? (5 Replies)
Discussion started by: gelitini
5 Replies
Login or Register to Ask a Question