Sponsored Content
Top Forums Shell Programming and Scripting Move files based on date in filename Post 302432650 by slatoms on Friday 25th of June 2010 04:13:18 PM
Old 06-25-2010
My goal is to move all but about the current month's worth of files so I ended up trying this...

Code:
for FILE in $( ls $instance_hpath/db2dump/db2diag*.log )
do
   FMONTH=$( echo $FILE | awk -F '-' '{print $3}' )
   FYEAR=$( echo $FILE | awk -F '-' '{print $2}' )
   case "$FMONTH" in
   01) FMONTH=Jan;
   ;;
   02) FMONTH=Feb;
   ;;
   03) FMONTH=Mar;
   ;;
   04) FMONTH=Apr;
   ;;
   05) FMONTH=May;
   ;;
   06) FMONTH=Jun;
   ;;
   07) FMONTH=Jul;
   ;;
   08) FMONTH=Aug;
   ;;
   09) FMONTH=Sep;
   ;;
   10) FMONTH=Oct;
   ;;
   11) FMONTH=Nov;
   ;;
   12) FMONTH=Dec;
   ;;
   esac
   if [ $FMONTH != $(date +\%b) ]
   then
   FOLDER=$FMONTH'_'$FYEAR
   echo $FOLDER
   fi 
done

Your approach may be better since it pulls out all the eligible files before the looping starts. Thank you again.
 

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
CAL(1)							    BSD General Commands Manual 						    CAL(1)

NAME
cal -- displays a calendar SYNOPSIS
cal [-3hjry] [-A after] [-B before] [-d day-of-week] [-R reform-spec] [[month] year] DESCRIPTION
cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as follows: -3 Same as ``-A 1 -B 1''. -A after Display after months after the specified month. -B before Display before months before the specified month. -d day-of-week Specifies the day of the week on which the calendar should start. Valid values are 0 through 6, presenting Sunday through Saturday, inclusively. The default output starts on Sundays. -h Highlight the current day, if present in the displayed calendar. If output is to a terminal, then the appropriate terminal sequences are used, otherwise overstriking is used. If more than one -h is used and output is to a terminal, the current date will be high- lighted in inverse video instead of bold. -j Display Julian dates (days one-based, numbered from January 1). -R reform-spec Selects an alternate Gregorian reform point from the default of September 3rd, 1752. The reform-spec can be selected by one of the built-in names (see NOTES for a list) or by a date of the form YYYY/MM/DD. The date and month may be omitted, provided that what is specified uniquely selects a given built-in reform point. If an exact date is specified, then that date is taken to be the first missing date of the Gregorian Reform to be applied. -r Display the month in which the Gregorian Reform adjustment was applied, if no other month or year information is given. If used in conjunction with -y, then the entire year is displayed. -y Display a calendar for the current year. If no parameters are specified, the current month's calendar is displayed. A single parameter specifies the year and optionally the month in ISO format: ``cal 2007-12'' Two parameters denote the month (1 - 12) and year. Note that the century must be included in the year. A year starts on Jan 1. NOTES
In the USA and Great Britain the Gregorian Reformation occurred in 1752. By this time, most countries had recognized the reformation (although a few did not recognize it until the 1900's.) Eleven days following September 2, 1752 were eliminated by the reformation, so the calendar for that month is a bit unusual. In view of the chaotic way the Gregorian calendar was adopted throughout the world in the years between 1582 and 1928 make sure to take into account the date of the Gregorian Reformation in your region if you are checking a calendar for a very old date. cal has a decent built-in list of Gregorian Reform dates and the names of the countries where the reform was adopted: Italy Oct. 5, 1582 Denmark Feb. 19, 1700 Spain Oct. 5, 1582 Great Britain Sep. 3, 1752 Portugal Oct. 5, 1582 Sweden Feb. 18, 1753 Poland Oct. 5, 1582 Finland Feb. 18, 1753 France Dec. 12, 1582 Japan Dec. 20, 1872 Luxembourg Dec. 22, 1582 China Nov. 7, 1911 Netherlands Dec. 22, 1582 Bulgaria Apr. 1, 1916 Bavaria Oct. 6, 1583 U.S.S.R. Feb. 1, 1918 Austria Jan. 7, 1584 Serbia Jan. 19, 1919 Switzerland Jan. 12, 1584 Romania Jan. 19, 1919 Hungary Oct. 22, 1587 Greece Mar. 10, 1924 Germany Feb. 19, 1700 Turkey Dec. 19, 1925 Norway Feb. 19, 1700 Egypt Sep. 18, 1928 The country known as Great Britain can also be referred to as England since that has less letters and no spaces in it. This is meant only as a measure of expediency, not as a possible slight to anyone involved. HISTORY
A cal command appeared in Version 6 AT&T UNIX. BSD
December 21, 2007 BSD
All times are GMT -4. The time now is 05:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy