Help File Copy Historical Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help File Copy Historical Files
# 1  
Old 06-22-2011
Help File Copy Historical Files

Hello,

I have a directory /files/storage in which I have files having file name in format as follows

sabclin.yyyymmdd.0 e.g. sabclin.20110621.0 etc.

I want to copy all files that have a date in their file name i.e. yyyymmdd from today till 300 days in the past to another directory, I need to go by the date in the filename and not by -mtime on the file.

I would really appreciate your help.
# 2  
Old 06-22-2011
Hello,

You can get the date needed using the datecalc script provided in this forum otherwise , if you have oracle installed on your system, connect to it and get the date from there in the format and delete the files with that name.

Regards
Ravi
# 3  
Old 06-22-2011
Hello,

Thanks, but I do not follow. Date calc script? First I guess some how I need to get the date out from the file name isnt it? I am not quite sure how and then some how compare that date with todays date to see if days in between is less than or equal to 300 then copy over the file.

I did not quite understand the oracle part, I would like to accomplish it all in KSH.

Would appreciate any help
# 4  
Old 06-22-2011
Hello,

https://www.unix.com/answers-frequent...rithmetic.html

Gives you the details of how to extract date etc.

here is the snippet of your requirement:


Code:
 
get_JD () {
scale=0
echo " $1-32075+1461*($3+4800+($2-14)/12)/4+367*($2-2-($2-14)/12*12)/12-3*(($3+4900+($2-14)/12)/100)/4 " | bc
}

for file in the file list
do

first=`get_JD 1 1 2011` ## here pass the date extracted from first file
second=`get_JD 1 2 2011` ## here pass the current date
 
## date format passed dd mm yyyy format
 
diff=`expr $second - $first`
 
if [ $diff -ge 300 ]; then
cp $file destination_folder
fi

done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Script to copy the contents of two files into one file

Hi i need Script to copy the contents of two files into one file i have 2 fil X1.txt / X2.txt i need script to copy the contents of X1 and X2 In AllXfile X1.txt File X1 X2.txt File X2 AllXfile.txt File X1 File X2 (2 Replies)
Discussion started by: azzeddine2005
2 Replies

2. Shell Programming and Scripting

copy content of file to another files from certain position

Hello Guys I have a directory of xml files (almost 500 ) Now in each xml file 3 new attributes will be added which are in a different single file Is there any way I can copy the whole content of single file at 6th line of all the files in the directory . Thanks a lot!!! (7 Replies)
Discussion started by: Pratik4891
7 Replies

3. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

4. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

5. UNIX for Dummies Questions & Answers

copy files as space exist in file name..

Hi, i am having a directory in which files are having space in the name . $ls -1 aa b.txt my file.pdf lost file.csv foo_file.txti want to copy those file to some where with date +%F as extension . But it failed for the file having space. #!/bin/sh ls -1 >tt for var in `cat tt` do b=$var... (2 Replies)
Discussion started by: posix
2 Replies

6. Shell Programming and Scripting

Copy string from files into new file

I'm trying to copy a string (myame@yahoo.com) from multiple files and save them to a new file. This is what's I've gathered so far: sed 's/string/g' file.txt > output.txt Not sure how to run this on multiple files and extract just the email address found in each file. Any help would be... (2 Replies)
Discussion started by: rdell
2 Replies

7. Solaris

Copy files from the file to another directory

I have created a file that has list of all the files I want to copy into another directory.Is there a way to do it? Thanks In advance (4 Replies)
Discussion started by: shreethik
4 Replies

8. Shell Programming and Scripting

How to check a file exist and do a copy of other files

Hi, I would like to perform bash which would check the file A.txt to be size 0 or not. If the size is 0, I would copy file B.txt to replace A.txt. Please help. Thanks. -Jason (6 Replies)
Discussion started by: ahjiefreak
6 Replies

9. Shell Programming and Scripting

copy files dynamically from within a file

Hello All, I am given a file in which there are all the library files: lib.txt: /home/xyz/lib/*.jar /home/abc/java/*.jar /home/def/lib/a.jar /home/def/lib/b.jar ... My script should copy these files within lib.txt to current directory script: cd /home/$APP Please help. chiru (1 Reply)
Discussion started by: chiru_h
1 Replies

10. UNIX for Dummies Questions & Answers

historical ps

Hi there I am trying to find out what processes were running on my sun solaris 5.8 server yesterday. There are no jobs running on the server which are monitoring/logging processes on the server. Is there a way to find this out - is there an operating system log for processes? Thanks in... (4 Replies)
Discussion started by: niamh
4 Replies
Login or Register to Ask a Question