Monday, November 4, 2013

Help in Writing Shell - Date Validation

www.unixbabuforum.inI have a file named - rates.txt.20130630. 

I want to write a shell script to extract the date from the above file name, validate whether the date is yesterday'date. 
If true then, copy the file with the name rates.txt 

How can I write this shell?

www.unixbabuforum.inyou have to change extension (date) of "file" according 
to current date. 


file=rates.txt.20130630 
ext="${file##*.}" 
new_file=`echo $file | sed 's/\(.*\)\..*/\1/'` 
dt=`date -d '1 day ago' +"%Y%m%d"` 
if [ $ext -eq $dt ] 
then 
cp $file $new_file 
fi

0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM