The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-25-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
There are many ways in doing it... one is based on the time the file created in the system and the other way is based on date in the file name...

There will be a problem with the first method if the latest file ftp'd before the old files... old files will have latest file creation date than latest files and will move latest files to the archive folder...

Hence I adopted the second method which archives the file based on the date in the file name... hope this helps.


Code:
#!/usr/bin/ksh

for name in $(ls acme* | sed 's/_[0-9]*.txt//g' | uniq)
do
   cnt=0
   for fname in $(ls $name* | sed 's/_\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/_\3\1\2/g' | sort -r )
   do
      echo $fname
      nm=$(echo $fname | sed 's/_\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/_\2\3\1/g' )
      cnt=$(($cnt+1));
      if [ $cnt -ne 1 ]
      then
          mv $nm  ./bkup
          echo "$nm moved to backup"
      fi
   done
done

I have tested and it worked fine...