Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

incrementing numbers
We recieve zip files in the following format...yyyymmdd-#.zip where #
starts at 1 and increments up to 79. I need to unzip these files into
seperate folders based on a specified folder name. Here is what I
have....


BEGIN{
timetab(z,time() - 86400)

printf("c:\\progra~1\\winzip\\wzunzip.exe -e -s %s%02s%02s-.zip c:\
\test\\1\n",z["YEAR"],z["MONTH"],z["DAY"])  > "test.bat"
printf("c:\\progra~1\\winzip\\wzunzip.exe -e -s %s%02s%02s-.zip c:\
\test\\2\n",z["YEAR"],z["MONTH"],z["DAY"])  > "test.bat"

}

As you can see I have the date portion down its the # after the dash
in the zip name I don't know how to do. I'm pretty sure I need the ++
but not sure how.

thanks.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-06-08 11:58 PM


Re: incrementing numbers
On Mar 6, 1:25=A0pm, tcdrake <rymi...@gmail.com> wrote:
> We recieve zip files in the following format...yyyymmdd-#.zip where #
> starts at 1 and increments up to 79. I need to unzip these files into
> seperate folders based on a specified folder name. Here is what I
> have....
>
> BEGIN{
> timetab(z,time() - 86400)
>
> printf("c:\\progra~1\\winzip\\wzunzip.exe -e -s %s%02s%02s-.zip c:\
> \test\\1\n",z["YEAR"],z["MONTH"],z["DAY"]) =A0> "test.bat"
> printf("c:\\progra~1\\winzip\\wzunzip.exe -e -s %s%02s%02s-.zip c:\
> \test\\2\n",z["YEAR"],z["MONTH"],z["DAY"]) =A0> "test.bat"
>
> }
>
> As you can see I have the date portion down its the # after the dash
> in the zip name I don't know how to do. I'm pretty sure I need the ++
> but not sure how.
>
> thanks.


I think I need to add more info....

We have 80 zip files coming into one FTP directory each day labled
yyyymmdd-(store number).zip. These will then need to be extracted to
the folder associated to each location. The location folder name is
random and does not match the store number in the zip name. So from
what I gather one way would be to scan the FTP incoming directory to
get the ZIP names, not sure how to do this in awk. I also need to
figure out how to match the zip to the correct folder it needs to be
extracted to. Any ideas?

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-06-08 11:58 PM


Re: incrementing numbers
On Thu, 06 Mar 2008 12:44:23 -0800, tcdrake wrote:

> On Mar 6, 1:25_pm, tcdrake <rymi...@gmail.com> wrote: 
>
>
> I think I need to add more info....
>
> We have 80 zip files coming into one FTP directory each day labled
> yyyymmdd-(store number).zip. These will then need to be extracted to the
> folder associated to each location. The location folder name is random and
> does not match the store number in the zip name. So from what I gather one
> way would be to scan the FTP incoming directory to get the ZIP names, not
> sure how to do this in awk. I also need to figure out how to match the zip
> to the correct folder it needs to be extracted to. Any ideas?


XP batch plus gawk is my strong suite.  That code is broken from the batch
point of view.  In any case, I think a different approach is needed, one
based on gawk specific functions.  I would start with a batch wrapper

@echo off
dir /b ftp_directory | awk -fscript > }{.bat

I can only do part of the script without knowing how to map the location
number to the target directory (I'll do this in fully expanded syntax for
clarity)

BEGIN{
UnZip Command1 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s "
UnZip Command2 =
}

{
match( $0, /([0-9]+)-([0-9]+)\.zip, Array)
FileNameDate = Array[ 1 ]
Location = Array[ 2 ]
}
.....

Actually, it's easier to do a a pure batch file.

for /f "tokens=1,2,3 delims=.-" %%A in ('dir /b *.zip') do
"c:\program files\winzip\wzunzip.exe" -e -s %%A%-%B.%%C c:\test\%%B\

All one line.  Not tested (I'm running out of time and don't have WinZip
anyway).

--
T.E.D. (tdavis@mst.edu)



Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
03-06-08 11:58 PM


Re: incrementing numbers
On Mar 6, 3:47=A0pm, Ted Davis <tda...@umr.edu> wrote:
> On Thu, 06 Mar 2008 12:44:23 -0800, tcdrake wrote: 
> 
> 
> 
 
> 
> 
> 
 
nd 
ne 
t 
ip 
>
> XP batch plus gawk is my strong suite. =A0That code is broken from the bat=[/color
]
ch
> point of view. =A0In any case, I think a different approach is needed, one=[/color
]

> based on gawk specific functions. =A0I would start with a batch wrapper
>
> =A0 @echo off
> =A0 dir /b ftp_directory | awk -fscript > }{.bat
>
> I can only do part of the script without knowing how to map the location
> number to the target directory (I'll do this in fully expanded syntax for
> clarity)
>
> =A0 BEGIN{
> =A0 =A0 =A0 =A0 UnZip Command1 =3D "c:\\progra~1\\winzip\\wzunzip.exe -e -=[/color
]
s "
> =A0 =A0 =A0 =A0 UnZip Command2 =3D
> =A0 }
>
> =A0 {
> =A0 =A0 =A0 =A0 match( $0, /([0-9]+)-([0-9]+)\.zip, Array)
> =A0 =A0 =A0 =A0 FileNameDate =3D Array[ 1 ]
> =A0 =A0 =A0 =A0 Location =3D Array[ 2 ]
> =A0 }
> .....
>
> Actually, it's easier to do a a pure batch file.
>
> =A0 for /f "tokens=3D1,2,3 delims=3D.-" %%A in ('dir /b *.zip') do
> "c:\program files\winzip\wzunzip.exe" -e -s %%A%-%B.%%C c:\test\%%B\
>
> All one line. =A0Not tested (I'm running out of time and don't have WinZip=[/color
]

> anyway).
>
> --
> T.E.D. (tda...@mst.edu)- Hide quoted text -
>
> - Show quoted text -

Thanks T.E.D. I'll have to spend some time checking this out but will
update if/when I run into trouble.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-07-08 11:59 PM


Re: incrementing numbers
On Mar 7, 8:01=A0am, tcdrake <rymi...@gmail.com> wrote:
> On Mar 6, 3:47=A0pm, Ted Davis <tda...@umr.edu> wrote:
>
>
>
>
> 
 
 
> 
> 
> 
in 
t 
> 
> 
> 
he 
and 
one 
not 
zip 
> 
atch 
ne 
> 
> 
 
r 
> 
-s " 
> 
> 
> 
> 
ip 
> 
> 
>
> Thanks T.E.D. I'll have to spend some time checking this out but will
> update if/when I run into trouble.- Hide quoted text -
>
> - Show quoted text -

Here is where I am at....

I tried the batch file. Unfortunitly with what you had the zip name
ended up have the letters EB in it. Here is the output I recieved.

C:\tawk>"c:\program files\winzip\wzunzip.exe" -e -s 20080305EB. c:\test
\zip\
WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved

Password?

ERROR: Zip file 20080305EB. does not exist
Program is terminating!

The zip file name was 20080305-30.zip. I changed the batch and deleted
the %B reference. This caused the zip to be unzipped to the root of
test folder.


Let me try to give me info on what I am trying to do.

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.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-07-08 11:59 PM


Re: incrementing numbers
On Mar 7, 9:25=A0am, tcdrake <rymi...@gmail.com> wrote:
> On Mar 7, 8:01=A0am, tcdrake <rymi...@gmail.com> wrote:
>
>
>
>
> 
> 
# 
to 
> 
> 
 
 
> 
h in 
but 
> 
> 
> 
the 
om and 
er one 
, not 
he zip 
> 
batch 
one 
r
> 
> 
on 
for 
> 
-e -s " 
> 
> 
> 
> 
nZip 
> 
> 
> 
> 
>
> Here is where I am at....
>
> I tried the batch file. Unfortunitly with what you had the zip name
> ended up have the letters EB in it. Here is the output I recieved.
>
> C:\tawk>"c:\program files\winzip\wzunzip.exe" -e -s 20080305EB. c:\test
> \zip\
> WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
> Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved
>
> Password?
>
> ERROR: Zip file 20080305EB. does not exist
> Program is terminating!
>
> The zip file name was 20080305-30.zip. I changed the batch and deleted
> the %B reference. This caused the zip to be unzipped to the root of
> test folder.
>
> Let me try to give me info on what I am trying to do.
>
> 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 -
>
> - Show quoted text -

I misspoke earlier about the batch file. It did work after I edited
the batch but the command was not what I was expecting. Here is what
the batch file shows when I run it.

C:\tawk>for /F "tokens=3D1,2,3 delims=3D-" %A in ('dir /b *.zip') do "c:
\program files\winzip\wzunzip.ex
e" -e -s %A.%C c:\test\%B\

C:\tawk>"c:\program files\winzip\wzunzip.exe" -e -s 20080305E.zip. c:
\test\\
WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved

Password? *******************

Zip file: 20080305E.zip

The E should not be at the end of the zip file. The zip file is really
named 20080305-30.zip. Thought I would mention that.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-07-08 11:59 PM


Re: incrementing numbers
On Mar 7, 9:25=A0am, tcdrake <rymi...@gmail.com> wrote:
> On Mar 7, 8:01=A0am, tcdrake <rymi...@gmail.com> wrote:
>
>
>
>
> 
> 
# 
to 
> 
> 
 
 
> 
h in 
but 
> 
> 
> 
the 
om and 
er one 
, not 
he zip 
> 
batch 
one 
r
> 
> 
on 
for 
> 
-e -s " 
> 
> 
> 
> 
nZip 
> 
> 
> 
> 
>
> Here is where I am at....
>
> I tried the batch file. Unfortunitly with what you had the zip name
> ended up have the letters EB in it. Here is the output I recieved.
>
> C:\tawk>"c:\program files\winzip\wzunzip.exe" -e -s 20080305EB. c:\test
> \zip\
> WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
> Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved
>
> Password?
>
> ERROR: Zip file 20080305EB. does not exist
> Program is terminating!
>
> The zip file name was 20080305-30.zip. I changed the batch and deleted
> the %B reference. This caused the zip to be unzipped to the root of
> test folder.
>
> Let me try to give me info on what I am trying to do.
>
> 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 -
>
> - Show quoted text -

Below is the closest I have gotten so far but I still could use some
help.

for /f "tokens=3D1,2,3 delims=3D-" %%A in ('dir /b *.zip') do "c:\program
files\winzip\wzunzip.exe" -e -s %%A%-%.%%C c:\test\%B\

The output looks like this...

C:\tawk>for /F "tokens=3D1,2,3 delims=3D-" %A in ('dir /b *.zip') do "c:
\program files\winzip\wzunzip.ex
e" -e -s %A.%C c:\test\B\

C:\tawk>"c:\program files\winzip\wzunzip.exe" -e -s 20080305E.zip. c:
\test\B\


So what I need to figure out is why the E is showing up in the zip
name instead of the -(location number). Also why the directory B is
being reference instead of the location number.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-07-08 11:59 PM


Re: incrementing numbers
On Fri, 07 Mar 2008 07:32:06 -0800, tcdrake wrote:
> Zip file: 20080305E.zip
>
> The E should not be at the end of the zip file. The zip file is really
> named 20080305-30.zip. Thought I would mention that.

I made a typo %-%B should be -%%B

I'll look into the rest of it - it's not hard, but I just don't have time
right now.

--
T.E.D. (tdavis@mst.edu)



Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
03-07-08 11:59 PM


Re: incrementing numbers
On Mar 7, 9:41=A0am, tcdrake <rymi...@gmail.com> wrote:
> On Mar 7, 9:25=A0am, tcdrake <rymi...@gmail.com> wrote:
>
>
>
>
> 
> 
> 
re # 
into 
 
> 
> 
:\ 
:\ 
> 
ash in 
+ but 
> 
> 
> 
 
to the 
ndom and 
ther one 
es, not 
the zip 
> 
he batch 
d, one 
per
> 
> 
tion 
x for 
> 
e -e -s " 
> 
> 
> 

> 
WinZip 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>
> Below is the closest I have gotten so far but I still could use some
> help.
>
> for /f "tokens=3D1,2,3 delims=3D-" %%A in ('dir /b *.zip') do "c:\program
> files\winzip\wzunzip.exe" -e -s %%A%-%.%%C c:\test\%B\
>
> The output looks like this...
>
> C:\tawk>for /F "tokens=3D1,2,3 delims=3D-" %A in ('dir /b *.zip') do "c:
> \program files\winzip\wzunzip.ex
> e" -e -s %A.%C c:\test\B\
>
> C:\tawk>"c:\program files\winzip\wzunzip.exe" -e -s 20080305E.zip. c:
> \test\B\
>
> So what I need to figure out is why the E is showing up in the zip
> name instead of the -(location number). Also why the directory B is
> being reference instead of the location number.- Hide quoted text -
>
> - Show quoted text -

One thing I relized was I didn't have the zip file in the directory I
was running the batch file from...oops. Now with that said it still
doesn't work. Here is what I get....

C:\test>for /F "tokens=3D1,2,3 delims=3D-" %A in ('dir /b *.zip') do "c:
\program files\winzip\wzunzip.ex
e" -e -s %A.%C c:\test\B\

C:\test>"c:\program files\winzip\wzunzip.exe" -e -s 20080123. c:\test\B
\

So the zip file doesn't have the -(location).zip only yyyymmdd.
Also the folder created under test, folder B, shouldn't be B it should
be the location number.

Thanks.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-07-08 11:59 PM


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

> On Mar 7, 9:25_am, tcdrake <rymi...@gmail.com> wrote: 

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_director
y

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

@echo 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 "@echo 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)

@echo 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@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).



Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
03-08-08 02:58 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:51 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.