Need script to select multiple files from archive directory based on the date range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to select multiple files from archive directory based on the date range
# 1  
Old 01-22-2010
Need script to select multiple files from archive directory based on the date range

hi all,

here is the description to my problem.

input parameters: $date1 & $date2

based on the range i need to select the archived files from the archived directory and moved them in to working directory.

can u please help me in writing the code to select the multiple files based on the date range.

i need it urgently.today eod is the delivery of the code


Thanks,
Chandu.
# 2  
Old 01-22-2010
you need provide the file name format and date format.

Give some samples to us.
# 3  
Old 01-22-2010
eg: $date1 :20090301
$ date2: 20090502

archivefile dir : /projects/home01/archive/2009/

file names:

20090311_archival.txt
20090312_archival.txt
20090313_archival.txt
20090314_archival.txt

(here is small examle there may be so many files to transfer from archive dir)

need a script to move the files from archive dir to current direct
# 4  
Old 01-22-2010
Code:
Not tested:

#! /usr/bin/bash

BASE=/projects/home01/archive
DEST=/tmp

for file in `find $BASE -type f -name "*.txt"`
do
   date=$(echo $FILE|awk -F[\/_] '{print $(NF-1)}')
   if [ "$date" > "$1" && "$date" < "$2" ] ; then 
       mv $file $DEST/$file
   fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies

2. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

3. UNIX for Dummies Questions & Answers

Select all files in a folder based on creation date (ls command)

Hi All, <Re-posting in Correct group> I'm trying to select all the files in a folder that starts with a particular name format and are created in a gven date range using 'ls' command...but i'm not successful.... Example : I'm trying to see all the text files in a folder who names start... (6 Replies)
Discussion started by: Satya C1
6 Replies

4. 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

5. Shell Programming and Scripting

Moving files from one directory to another based on 2 date variables

Hi All, I am currently coding for a requirement(LINUX OS) where I am supposed to move a file (Lets Call it Employee.txt) from Directory A to Directory B based on 2 date fields as below, Date_Current = 20120620 Date_Previous = 20120610 Source Directory : /iis_data/source Target... (11 Replies)
Discussion started by: dsfreddie
11 Replies

6. Emergency UNIX and Linux Support

How to move files from a directory which falls between Date Range?

Hi All, I am trying to to move files from a directory to another which falls from Current day - 7 days. The files are in zipped format with dates appended on it. Can you pls help me as this came as a immediate change before the production Release planned next week. Pls let me know if... (11 Replies)
Discussion started by: dsfreddie
11 Replies

7. Shell Programming and Scripting

Help with Archiving multiple files based on name and date

Dear Gurus, I am a novice in shell scripts. I have a requirement where I need to move files every day from Current Folder to Archive folder. Daily I will be receiving 5 files in the folder - /opt/data/feeds/. The feeds folder has two sub-folders - Current and Archive. For example the... (25 Replies)
Discussion started by: shankar1dada
25 Replies

8. Programming

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

9. Shell Programming and Scripting

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies
Login or Register to Ask a Question