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

Re: incrementing numbers
On Mar 7, 8:58=A0pm, Ted Davis <tda...@umr.edu> wrote:
> On Fri, 07 Mar 2008 07:32:06 -0800, tcdrake 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.
>
> =A0 @echo off
> =A0 dir /b *.zip | awk -fscript_file.awk map_file.txt - > }{.cmd
>
> when satisfied that }{.cmd does what you want, add these two lines
>
> =A0 call }{
> =A0 del }{.cmd
>
> The script is commented and in fully expanded syntax for clarity.
>
> BEGIN{
> =A0 =A0 =A0 =A0 UnZipCommand1 =3D "c:\\progra~1\\winzip\\wzunzip.exe -e -s=[/color
]
"
> =A0 =A0 =A0 =A0 UnZipCommand2 =3D " c:\\test\\"
> # Making the field separator -, ., or TAB makes it work for both
> # the file name and the tab delimited map file.
> =A0 =A0 =A0 =A0 FS =3D "[-.\t]"
> =A0 =A0 =A0 =A0 print "@echo off"}
>
> {
> =A0 =A0 =A0 =A0 if( NR =3D=3D FNR ) {
> # The file containing the location map.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Table[ $1 ] =3D $2
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 else {
> # The directory listing on STDIN
>
> # The source is the filename in the DIR listing.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Fname =3D $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).
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Target =3D Table[ $2 ]
> # It may be desirable to ad a trailing "\\" to the command.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Command =3D UnZipCommand1 Fname UnZipComma=[/color
]
nd2 Target
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print Command
> =A0 =A0 =A0 =A0 }
>
> }
>
> 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 =A0 =A0 =A0 101
> 2 =A0 =A0 =A0 102
> 3 =A0 =A0 =A0 103
> 4 =A0 =A0 =A0 104
> 5 =A0 =A0 =A0 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. (tda...@mst.edu) MST (Missouri University of Science and Technology=[/color
]
)
> used to be UMR (University of Missouri - Rolla).

After installing GAWK everything worked. Thank you for all your help.

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-11-08 03:01 AM


Re: incrementing numbers
On Mar 10, 9:22=A0am, tcdrake <rymi...@gmail.com> wrote:
> On Mar 7, 8:58=A0pm, Ted Davis <tda...@umr.edu> wrote:
>
>
> 
p, 
e 
to 
. 
de 
> 
f 
> 
 
> 
> 

> 
> 
> 
> 
> 
-s " 
> 
> 
mand2 Target 
> 
> 
> 
> 
> 
> 
> 
> 
> 
gy) 
>
> After installing GAWK everything worked. Thank you for all your help.

I have run across something else I would like. I only need certain
files unzipped. I know in winzip I can call a list which has all the
files I want to unzip. The command for this is wzunzip.exe -e -s
20080307-5.zip @list.txt c:\test\105. Any chance you can assist in
adding this feature?

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-13-08 12:01 AM


Re: incrementing numbers
On Wed, 12 Mar 2008 12:46:29 -0700, tcdrake wrote:
>
> I have run across something else I would like. I only need certain files
> unzipped. I know in winzip I can call a list which has all the files I
> want to unzip. The command for this is wzunzip.exe -e -s 20080307-5.zip
> @list.txt c:\test\105. Any chance you can assist in adding this feature?


Replace
dir /b *.zip | awk -fscript_file.awk map_file.txt - > }{.cmd
in the batch file with
awk -fscript_file.awk map_file.txt filelist > }{.cmd

All the DIR command did was to generate a list of all the .zip files - if
you already have a list of files to process, then that's not needed.  Good
thing I wrote that script so it didn't care where its input came from.

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



Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
03-13-08 12:01 AM


Re: incrementing numbers
On Mar 12, 3:04=A0pm, Ted Davis <tda...@umr.edu> wrote:
> On Wed, 12 Mar 2008 12:46:29 -0700, tcdrake wrote:
> 
 

>
> Replace
> =A0 dir /b *.zip | awk -fscript_file.awk map_file.txt - > }{.cmd
> in the batch file with
> =A0 awk -fscript_file.awk map_file.txt filelist > }{.cmd
>
> All the DIR command did was to generate a list of all the .zip files - if
> you already have a list of files to process, then that's not needed. =A0Go=[/color
]
od
> thing I wrote that script so it didn't care where its input came from.
>
> --
> T.E.D. (tda...@mst.edu)

TED,
Thanks for the quick reply. I didn't make myself clear. You original
script is great and I really do appreciate it. The only change I need
is adding @list.txt to the end of each zip file. So the original code
is...

BEGIN{
UnZipCommand1 =3D "c:\\progra~1\\winzip\\wzunzip.exe -e -s "
UnZipCommand2 =3D " c:\\test\\"


I need to put in @list.txt after the zip name. So somehow getting to
look like this...

BEGIN{
UnZipCommand1 =3D "c:\\progra~1\\winzip\\wzunzip.exe -e -s
@list.txt"
UnZipCommand2 =3D " c:\\test\\"

So the output is 20080311-1.zip @list.txt. This will allow me to only
unzip the files I need out of the zip. Make sense?

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-13-08 12:01 AM


Re: incrementing numbers
On Wed, 12 Mar 2008 13:23:37 -0700, tcdrake wrote:

> On Mar 12, 3:04_pm, Ted Davis <tda...@umr.edu> wrote: 
>
> TED,
> Thanks for the quick reply. I didn't make myself clear. You original
> script is great and I really do appreciate it. The only change I need is
> adding @list.txt to the end of each zip file. So the original code is...
>
> BEGIN{
>         UnZipCommand1 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s "
>         UnZipCommand2 = " c:\\test\\"
>
>
> I need to put in @list.txt after the zip name. So somehow getting to look
> like this...
>
> BEGIN{
>         UnZipCommand1 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s
> @list.txt"
>         UnZipCommand2 = " c:\\test\\"
>
> So the output is 20080311-1.zip @list.txt. This will allow me to only
> unzip the files I need out of the zip. Make sense?

The only think that can be unzipped is a zip archive - you want to extract
individual files based on a list.

Change

UnZipCommand2	= " c:\\test\\"

in the script to

UnZipCommand2	= " @list.txt c:\\test\\"

--

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-13-08 02:59 AM



http://www.CheapVideoBlog.com/Media....asp?vid=726071

Report this thread to moderator Post Follow-up to this message
Old Post
Edmoterhated2
03-13-08 10:44 PM


Re: incrementing numbers
On Mar 12, 8:03=A0pm, Ted Davis <tda...@umr.edu> wrote:
> On Wed, 12 Mar 2008 13:23:37 -0700, tcdrake wrote: 
> 
> 
 
> 
 
e 
> 
> 
 

> 
" 
> 
k 
> 
 
> 
>
> The only think that can be unzipped is a zip archive - you want to extract=[/color
]

> individual files based on a list.
>
> Change
>
> =A0 UnZipCommand2 =3D " c:\\test\\"
>
> in the script to
>
> =A0 UnZipCommand2 =3D " @list.txt c:\\test\\"
>
> --
>
> T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology=[/color
]
)
> used to be UMR (University of Missouri - Rolla).

T.E.D,
Thank you for all your assitance with this. I could use a little more
help though. I posted this earlier this morning but thought I would
also respond to this post since you were so helpful.


I have a couple of scripts which for the most part work but I need to
change it up a bit based on new requirments. Here is what is currently
happening.

Get 80 zip files in named yyyymmdd-(location).zip
Unzip each zip to a folder based on location code in zip name.
Rename the files to include yesterdays date.
Zip up files and move to anyother directory based on location code.

All the above works fine if I only get one zip file per location per
day. This is an issue when I get more than one zip file per location.
So if I get 20080323-1.zip and 20080324-1.zip because the code I am
using will just unzip the first one then unzip the second to the same
folder which will over write the first ones before I am able to rename
them.

What I need to do is unzip and rename the files based on the date of
the zip file then zip all of the files into one zip based on
yyyymmdd.zip.

Here is my current code which came with a lot of help from this group
and a forum :)

CODE BELOW


@echo off
cd\
cd po\test\users\test
dir /b *.zip | awk -f  C:\test\unzip.awk  C:\stores.txt - > C:
\unzip.cmd
The above calls the awk code below
CODE
BEGIN{
UnZipCommand1 =3D "c:\\progra~1\\winzip\\wzunzip.exe -e -s C:\\po
\\test\\users\\test\\"
UnZipCommand2 =3D " @list.txt C:\\po\\test\\users\\test\\"
# Making the field separator -, ., or TAB makes it work for both
# the file name and the tab delimited map file.
FS =3D "[-.\t]"
print "@echo off"


}


{
if( NR =3D=3D FNR ) {
# The file containing the location map.
Table[ $1 ] =3D $2
}
else {
# The directory listing on STDIN

# The source is the filename in the DIR listing.
Fname =3D $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 =3D Table[ $2 ]
# It may be desirable to ad a trailing "\\" to the command.
Command =3D UnZipCommand1 Fname UnZipCommand2 Target
print Command
}



}

Then I run the following to rename the files based on the date, zip
and move to the correct directory.

CODE BELOW


BEGIN{

i=3D0
timetab(z,time() - 86400)
while (i < 2){
yesterday =3D time()-(i*86400)
timetab(y,yesterday)
{
while ( (getline < "Stores.txt") > 0)
{
printf("REN c:\\po\test\users\test\\%s\\emp.dbf em%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\gndtndr.dbf td%s%02s%02s.dbf
\n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\gndline.dbf ln%s%02s%02s.dbf
\n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\gnditem.dbf it%s%02s%02s.dbf
\n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\itm.dbf i%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\trans.log t%s%02s%02s.log\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\cit.dbf ci%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\cat.dbf ca%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\gndrevn.dbf gr%s%02s%02s.dbf
\n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\rev.dbf rv%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\gndturn.dbf gt%s%02s%02s.dbf
\n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\tdr.dbf t%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\pro.dbf p%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
printf("REN c:\\po\test\users\test\\%s\\cmp.dbf c%s%02s%02s.dbf\n",
$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
i++

}

while ( (getline < "Store.txt") > 0)

printf("c:\\progra~1\\winzip\\wzzip.exe -m -s C:\\po\test\users\test\\
%s\\%s%02s%02s.zip C:\\po\test\users\test\\%s\\*.*\n",
$1 ,z["YEAR"],z["MONTH"],z["DAY"], $1) > "C:\\test\\doit.bat"


}

while ((getline <"Store1.txt") > 0)
printf("XCOPY /s C:\\po\test\users\test\\%s\\*.zip C:\\iFtpSvc\\info\
\users\\download\\test\\%s\\\n",$1,$1) > "C:\\test\\doit.bat"

}


while ((getline <"Store2.txt") > 0)
printf("del C:\\po\test\users\test\\%s\\*.zip\n",$1) > "C:\\test\
\doit.bat"
printf("del C:\\po\test\users\test\\*.zip -w 10\n")  > "C:\\test\
\doit.bat"


}

I think one option is to have a piece of code which goes through the
directory and makes a list of all the files. Then use that list to
rename the unzipped files based on the list. I just not sure how to
implement it. Any ideas?

Report this thread to moderator Post Follow-up to this message
Old Post
tcdrake
03-27-08 12:03 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.