Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with moving file ranges

Status
Not open for further replies.

loki126

Technical User
May 13, 2005
3
US
I know this may be the wrong forum to post this in, but I really have no idea where else to post. I have a huge project which is quite simple to complete but will be extremely time-consuming. I have over 800,000 files and all files are named in numeric order. I have a list of over 1,000 ranges and I need to place the files corresponding to each range into its own folder which is named the beginning range. To better illustrate:

I have the Ranges-
000001-000009
000010-000013
000014-000015
etc...

Let's take the first range, 000001-000009. I have to create a folder and name the folder "000001". Then I need to place the files from 000001 through 000009 into the folder.

Again, I have over 1,000 of these ranges to do. I was wondering if there is any software or anything out there that completes this project for me?

Thank you VERY much for your help
 
I've had to make some assumptions:

1) your directory can't be in the current directory where your files are.

2) Your ranges are in the file called range.file and I'm assuming no errors in the ranges:

Code:
#!/bin/ksh

d=/tmp
typeset -Z6 z1 # right justify, zero fill 6 characters

while IFS="-" read c1 c2
do
   mydir=$d/$c1 # create initial directory, mydir
   mkdir -p $mydir

   # loop thru the range copying each file
   # if it exists
   while (( $c1 <= $c2 ))
   do
      z1=$c1 # zero fill regaining the full filename
      if [[ -n $(ls $z1 2>- ) ]]
      then
         cp "$z1" $mydir
      fi
      ((c1+=1))
   done

done < range.file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top