Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: incrementin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 16 Topic 2179 of 2236
Post > Topic >>

Re: incrementing numbers

by Ted Davis <tdavis@[EMAIL PROTECTED] > Mar 7, 2008 at 07:58 PM

On Fri, 07 Mar 2008 07:32:06 -0800, tcdrake wrote:

> On Mar 7, 9:25 am, tcdrake <rymi...@[EMAIL PROTECTED]
> wrote:
>> I get 80 zips each day. So today the zips will be named 20080306-1.zip,
>> 20080306-2.zip, 20080306-3.zip, etc.. The number after the dash is the
>> location number. I need to unzip each location to a folder based on
>> different location numbers. So location 1 based on the zip name goes to
>> location 090909. Location 2 based on the zip name goes to location
>> 034850987. I have an excel file which assigns locations to each other.
>> Does that help? I hope so as I could really use the help on this.- Hide
>> quoted text -
>>

I can't test this with TAWK - I'm not sure I even still have it on any of
my machines, definitely not on this one.

Assuming that the location map is exported from Excel as a tab delimited
file with each entry on a separate line in the form

number_in_filename\tdestination_directory

then this batch file generates another batch file to do the actual work.

  @[EMAIL PROTECTED]
 off
  dir /b *.zip | awk -fscript_file.awk map_file.txt - > }{.cmd

when satisfied that }{.cmd does what you want, add these two lines

  call }{
  del }{.cmd

The script is commented and in fully expanded syntax for clarity.

BEGIN{
	UnZipCommand1 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s "
	UnZipCommand2 = " c:\\test\\"
# Making the field separator -, ., or TAB makes it work for both
# the file name and the tab delimited map file.
	FS = "[-.\t]"
	print "@[EMAIL PROTECTED]
 off"
}
{
	if( NR == FNR ) {
# The file containing the location map.
		Table[ $1 ] = $2
	}
	else {
# The directory listing on STDIN

# The source is the filename in the DIR listing.
		Fname = $0
# The target is the given parent directory followed by the location
# from the map file corresponding to the location number in the
# file name (the second field).
		Target = Table[ $2 ]
# It may be desirable to ad a trailing "\\" to the command.
		Command = UnZipCommand1 Fname UnZipCommand2 Target 
		print Command
	}
}

If it doesn't work with TAWK, install gawk - it's better for almost
everything except that it doesn't have true multidimensional arrays and
isn't a compiler <http://gnuwin32.sourceforge.net/packages/gawk.htm>.

Using this map

1	101
2	102
3	103
4	104
5	105

and files named 20080307-1.zip,20080307-2.zip, 0080307-3.zip, 
20080307-4.zip, and 20080307-5.zip

it generated this output file (lines may have wrapped)

@[EMAIL PROTECTED]
 off
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-1.zip c:\test\101
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-2.zip c:\test\102
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-3.zip c:\test\103
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-4.zip c:\test\104
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-5.zip c:\test\105

-- 

T.E.D. (tdavis@[EMAIL PROTECTED]
) MST (Missouri University of Science and
Technology)
used to be UMR (University of Missouri - Rolla).




 16 Posts in Topic:
incrementing numbers
tcdrake <rymills@[EMAI  2008-03-06 11:25:29 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-06 12:44:23 
Re: incrementing numbers
Ted Davis <tdavis@[EMA  2008-03-06 15:47:19 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-07 06:01:26 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-07 07:25:05 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-07 07:32:06 
Re: incrementing numbers
Ted Davis <tdavis@[EMA  2008-03-07 15:04:41 
Re: incrementing numbers
Ted Davis <tdavis@[EMA  2008-03-07 19:58:45 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-07 07:41:51 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-07 13:06:05 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-10 07:22:41 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-12 12:46:29 
Re: incrementing numbers
Ted Davis <tdavis@[EMA  2008-03-12 15:04:55 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-12 13:23:37 
Re: incrementing numbers
Ted Davis <tdavis@[EMA  2008-03-12 20:03:31 
Re: incrementing numbers
tcdrake <rymills@[EMAI  2008-03-26 06:48:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 9:30:42 CDT 2008.