Sponsored Content
Top Forums Shell Programming and Scripting Move files based on date in filename Post 302432597 by slatoms on Friday 25th of June 2010 12:14:07 PM
Old 06-25-2010
Move files based on date in filename

I know this gets covered quite a bit in the forum and I think there is enough there for me to figure out how to do what I am trying to do, I just don't think I would do it very efficiently so I am going to ask the question...

I have database log files with date and time stamps in the file like
db2diag-2010-04-09-06.04.01.log in a directory in AIX

I want to process this directory of log files and where the date stamp in the file name is greater than 30 days old (I have roughly 6 months worth now) I want to move that file to another path and put it into the appropriate folder based on date where the naming is month-year format (like Apr-2010).

There's probably a thousand ways to think about this and I can only see the one right at the top of my mind, but I am guessing I need a loop where I parse the date out of each file name with pattern db2diag*.log, see if it's more than 30 days old and then use that date to figure out the name of the folder it needs to move to. I think with my knowledge level I'd probably be tempted to do that with a case statement so that when I parse the 04 out of the example file name I do something like (where $month equals 04)


Code:
case "$month" in 
1) month=Jan;
;;
2) month=Feb;
;;
3) month=Mar;
;;
4) month=Apr;
;;

.
.
.

ideas?
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to move files into different folders based on filename

I need to move a bunch of files into folders that have the same name. I wanted to either do this with some filter command or some type of batch file that I could save that would already include all of the mv commands since I will have to do this process often. Whatever method you think is easier. ... (7 Replies)
Discussion started by: italia5
7 Replies

2. UNIX for Dummies Questions & Answers

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (2 Replies)
Discussion started by: Sriranga
2 Replies

3. Shell Programming and Scripting

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (4 Replies)
Discussion started by: Sriranga
4 Replies

4. Shell Programming and Scripting

Move file based on filename

Hi All I need a script to manipulate files based on a filename: example filename: 66600_042706.pdf the script will create a directory 66000 only if this directory is not existing. If that directory is existing it will just move the file to 66000/666000_042706.pdf in addition, i want to... (4 Replies)
Discussion started by: aemestech
4 Replies

5. Shell Programming and Scripting

Get the oldest date based on date in the filename

I am using ksh93 on Solaris. Ok, this may seem like a simple request at first. I have a directory that contains sets of files with a YYYYMMDD component to the name, along with other files of different filespecs. something like this: 20110501_1.dat 20110501_2.dat 20110501_3.dat... (2 Replies)
Discussion started by: gary_w
2 Replies

6. Shell Programming and Scripting

Move all files from source to destination directory based on the filename

Move all files starting with a specific name to different directory. This shell script program should have three parameters File Name Source Directory Destination Directory User should be able to enter ‘AB_CD*' in file name parameter. In this case all the files starting with AB_CD will... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

7. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

8. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

9. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies
XCALPR(1)						      General Commands Manual							 XCALPR(1)

NAME
xcalpr - print xcal calendar entries SYNTAX
xcalpr [ -c ][ -x ][ -f file ][ -d dir ][ -u user ][ date-spec ] DESCRIPTION
Xcalpr prints the contents of the xcal files. It is intended to be used in situations when you have no access to an X screen. It can also be used to generate entries for the standard UNIX calendar program. With no arguments, it prints any entries that exist for the next seven days. The program also reads the contents of the seven daily files and prints them at the appropriate point in the output stream. Each line in the output is preceded by the day of the week, the day of the month, the month and the year. Xcalpr can be given a date specification to select months and years. If the date spec consists of just a year number, then all the data for that year is printed. For example: xcalpr 1994 will print all the data for 1994. Several years can be specified. If you give the name of a month, then the data for that month in the current year will be printed. If the month is in the past, then the data for that month next year will be printed. For example, if xcalpr oct jan is typed in August, xcalpr will print October in the current year and January next year. You can select a particular year by adding the number after any months that you need printing: xcalpr oct nov 1994 will print October and November in 1994. There are a couple of special `month' names. The name rest will print the data for the rest of the month, starting tomorrow. The rest argument is not recognised if you give a year as a parameter. If tomorrow happens to be the first day of the next month, then all the data for next month will be printed. The name next prints all the data for next month. OPTIONS
The -c option causes xcalpr to output lines suitable for input to the standard UNIX calendar program. The -d switch is followed by a directory name and specifies an alterative location for your Calendar directory. Your home directory is prepended if the name doesn't start with a slash or a dot. The -f option is followed by a file name and xcalpr will write it's output to that file, rather than standard output. The -u option is followed by a user name and dumps their calendar files rather than yours. The -x option makes xcalev operate with Calendar files that are compatible with the xcalendar program. FILES
$HOME/Calendar/* xc<dd><Mon><Year> A data file is day, Month in three letter format and the year. xy<Year> A year directory. xw<Day> A data file for the weekly code, one per day. SEE ALSO
xcal(1), xcalev(1), xcal_cal(1) AUTHOR
Copyright 1993 by Peter Collinson, Hillside Systems All rights reserved. This product includes software developed by the University of California, Berkeley and its contributors. X Version 11 R5 October 1993 XCALPR(1)
All times are GMT -4. The time now is 10:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy