The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using camcorder tapes to back up files iBot UNIX and Linux RSS News 0 12-20-2007 08:20 AM
Can I back up all the files I work with each day using tar? jo calamine Filesystems, Disks and Memory 2 10-01-2006 02:35 PM
How to remove 15days back old files vidya2006 Post Here to Contact Site Administrators and Moderators 2 05-18-2006 10:41 AM
Script to delete all data from multiple files uni_ajay_r Shell Programming and Scripting 5 03-29-2006 08:05 AM
Bring back removed files Reza Nazarian UNIX for Dummies Questions & Answers 2 07-23-2001 07:52 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2007
Registered User
 

Join Date: Jul 2006
Posts: 180
Back up of multiple data files

I have filesi in a direcotry that start with different names but have dates in the format 01212006. Along with these files there are also files with different dates. What i want to do is copy all the files that have 01212006 in them to 01072007 and move the old files to different directory.

For e.g file of interest : abc.01212006.1.dat
file of no interest abc.01262006.1.dat

I need the file of interest to be copied to abc.01072007.1.dat and then move the old file to diffrerent directory. How can I acheive this?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-07-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,223
Try...
Code:
#!/usr/bin/ksh

date="01212006"
newdate="01072007"

for file in *$date*
do
  [[ -f $file ]] || echo no files && exit 1
  newfile=$(echo $file|sed "s/$date/$newdate/")
  cp $file $newfile
  : etc
done
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0