Code Comments
Programming Forum and web based access to our favorite programming groups.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 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s C:\\po
\\test\\users\\test\\"
UnZipCommand2 = " @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 = "[-.\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
}
}
Then I run the following to rename the files based on the date, zip
and move to the correct directory.
CODE BELOW
BEGIN{
i=0
timetab(z,time() - 86400)
while (i < 2){
yesterday = 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?
Post Follow-up to this messagetcdrake escreveu:
> 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.
This is due the way you devised your solution as a series of batch
processess.
If you inline the calling of the commands instead of lumping them in
batch files to call then latter this would not be a problem.
Caveat emptor: very superficial analysis!
>
> 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 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s C:\\po
> \\test\\users\\test\\"
> UnZipCommand2 = " @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 = "[-.\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
> }
>
>
>
> }
>
> Then I run the following to rename the files based on the date, zip
> and move to the correct directory.
>
> CODE BELOW
>
>
> BEGIN{
>
> i=0
> timetab(z,time() - 86400)
> while (i < 2){
> yesterday = 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"
>
>
> }
This is half off-topic: This whole script could be substituted by a
doit.bat with three parameters to substitute directly in the batch file.
>
> 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?
Post Follow-up to this messageOn 3/26/2008 7:16 AM, tcdrake wrote: > 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. This is a totally inappropriate application for awk. Yes, you can probably h ack something together in awk to achieve your end result, but you could do that with an assembly code program too and that'd also be a poor approach. You should be doing this in whatever scripting language your OS supports. Post to an OS-specific NG (e.g. comp.unix.shell if you're in UNIX or can download cygwi n for Windows) for a good solution. Ed.
Post Follow-up to this messageOn Wed, 26 Mar 2008 05:16:13 -0700, tcdrake wrote:
> 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?
In your example code, you seem to be trying to rename the same files twice
to different names - that doesn't work. Also, you should not use getline
that way - it's so much better to pass the file name as an argument and
let awk take care of the file.
In a batch file:
for %%A in (*.dbf) do (
rename code here
%%~nA is the file's base name without the extesnion
%%~xA is the extension
%%~dA is the drive letter and colon
%%~pA is the directory
)
The only thing you need awk for is to generate the various date strings.
Your approach to generating date strings is *way* too complicated - it's
better to use
batch file
for /f "tokens=1,2" %%A in ('awk "BEGIN{print
strftime(\"%%Y%%m%%d\",systime()-86400) \" \"
strftime(\"%%Y%%m%%d\",systime()-2*86400)}"') do ( set yesterday=%%A& set
daybefore=%%B)
All one line. Then the two dates are in the named environment variables
in YYYYMMDD format. I don't see any reason for the daybefore, you your
code generates it.
So your big mess of way too complicated awk code seems to resolve to
@echo off
set base=c:\po\test\users\test\
for /f "tokens=1,2" %%A in ('awk "BEGIN{print
strftime(\"%%Y%%m%%d\",systime()-86400) \" \"
strftime(\"%%Y%%m%%d\",systime()-2*86400)}"') do ( set yesterday=%%A& set
daybefore=%%B)
for /f %%A in (stores.txt) do (
for %%B in ( %base%%%A\*.dbf) do ren %%B %%~nB%yesterday%%%~xB
)
Using gawk.exe in the Windows XP environment. Remember that real lines
are indented two spaces, lines indented less than that are wrapped from
the above line.
--
T.E.D. (tdavis@mst.edu)
Post Follow-up to this messageTed Davis escreveu:
> On Wed, 26 Mar 2008 05:16:13 -0700, tcdrake wrote:
>
>
> In your example code, you seem to be trying to rename the same files twice
> to different names - that doesn't work. Also, you should not use getline
> that way - it's so much better to pass the file name as an argument and
> let awk take care of the file.
>
Since again we're heading half off topic here...
> In a batch file:
> for %%A in (*.dbf) do (
> rename code here
> %%~nA is the file's base name without the extesnion
> %%~xA is the extension
> %%~dA is the drive letter and colon
> %%~pA is the directory
> )
>
> The only thing you need awk for is to generate the various date strings.
> Your approach to generating date strings is *way* too complicated - it's
> better to use
>
> batch file
> for /f "tokens=1,2" %%A in ('awk "BEGIN{print
> strftime(\"%%Y%%m%%d\",systime()-86400) \" \"
> strftime(\"%%Y%%m%%d\",systime()-2*86400)}"') do ( set yesterday=%%A& set
> daybefore=%%B)
>
> All one line. Then the two dates are in the named environment variables
> in YYYYMMDD format. I don't see any reason for the daybefore, you your
> code generates it.
The OP can elide all the AWK contortion using an appropriate port of the
unix utility date for its OS (which I surmise is a variety of Windows
due the use of winzip.exe):
C:\>c:\usr\local\wbin\date.exe
Wed Mar 26 18:06:59 BST 2008
C:\>c:\usr\local\wbin\date.exe -d yesterday
Tue Mar 25 18:07:07 BST 2008
C:\>c:\usr\local\wbin\date.exe -d "2 days ago"
Mon Mar 24 18:07:13 BST 2008
These dates can be formated as above:
C:\>c:\usr\local\wbin\date.exe +%Y%m%d
20080326
C:\>c:\usr\local\wbin\date.exe-d yesterday +%Y%m%d
20080325
C:\>c:\usr\local\wbin\date.exe -d "2 days ago" +%Y%m%d
20080324
HTH
Post Follow-up to this messageOn Wed, 26 Mar 2008 18:18:11 -0300, Cesar Rabak wrote: > > The OP can elide all the AWK contortion using an appropriate port of the > unix utility date for its OS (which I surmise is a variety of Windows due > the use of winzip.exe): > > > C:\>c:\usr\local\wbin\date.exe > Wed Mar 26 18:06:59 BST 2008 > > C:\>c:\usr\local\wbin\date.exe -d yesterday Tue Mar 25 18:07:07 BST 2008 > > C:\>c:\usr\local\wbin\date.exe -d "2 days ago" Mon Mar 24 18:07:13 BST > 2008 > > These dates can be formated as above: > > C:\>c:\usr\local\wbin\date.exe +%Y%m%d 20080326 > > C:\>c:\usr\local\wbin\date.exe-d yesterday +%Y%m%d 20080325 > > C:\>c:\usr\local\wbin\date.exe -d "2 days ago" +%Y%m%d 20080324 > True, but this is an awk group: he is known to have gawk and TAWK, but is not known to have any of the other highly useful Gnu ports. (<http://gnuwin32.sourceforge.net/packages.html> ) -- T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology) used to be UMR (University of Missouri - Rolla).
Post Follow-up to this messageOn Mar 26, 7:10=A0pm, Ted Davis <tda...@umr.edu> wrote: > On Wed, 26 Mar 2008 18:18:11 -0300, Cesar Rabak wrote: > e > > > > > > > > > True, but this is an awk group: he is known to have gawk and TAWK, but > is not known to have any of the other highly useful Gnu ports. > (<http://gnuwin32.sourceforge.net/packages.html> ) > > -- > > T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology=[/color ] ) > used to be UMR (University of Missouri - Rolla). Thank you for everyones input and sorry for the delay in my response. Yes, I do agree that I have a mess on my hands. Doing the best I can with the limited knowledge I have. With that said I don't believe I am renaming the files twice. I unzip only certain files from the ZIP and put them in the correct directory. From there I rename them from emp.dbf to em080325.dbf. 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" I then zip and move to another directory. All that works right now. I took a look at your script T.E.D and please correct me if I missunderstood what you have. It looks like your code seems to rename the dbf to yesterdays date. I also undertand you as saying that small bit of code makes my mess of a code no longer needed. Which part is no longer needed? I ask because your not unzipping/zipping. Is your code supposed to fit into a portion of the awk or batch code I already have?
Post Follow-up to this messageOn Mar 28, 10:30=A0am, tcdrake <rymi...@gmail.com> wrote:
> On Mar 26, 7:10=A0pm, Ted Davis <tda...@umr.edu> wrote:
>
>
>
>
he
due
>
>
08
>
>
>
>
>
>
>
>
gy)
>
> Thank you for everyones input and sorry for the delay in my response.
>
> Yes, I do agree that I have a mess on my hands. Doing the best I can
> with the limited knowledge I have. With that said I don't believe I am
> renaming the files twice. I unzip only certain files from the ZIP and
> put them in the correct directory. From there I rename them from
> emp.dbf to em080325.dbf.
>
> 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"
>
> I then zip and move to another directory. All that works right now.
>
> I took a look at your script T.E.D and please correct me if I
> missunderstood what you have. It looks like your code seems to rename
> the dbf to yesterdays date. I also undertand you as saying that small
> bit of code makes my mess of a code no longer needed. Which part is no
> longer needed? I ask because your not unzipping/zipping. Is your code
> supposed to fit into a portion of the awk or batch code I already have?
Well started over and simplified the code with everyone's assistance.
I set it to unzip to a working directory, rename files, zip and move
to the correct directory based on the location code. Then process the
next zip. Here is it for everyone to see.
BEGIN{
while ( (getline < "stores.txt") > 0)
{
FILENOZIP =3D substr($0,1,(length($0) - 4))
FILEDATE =3D substr($0,1,8)
FILEDATESHRTYR =3D substr($0,3,6)
STORENUM =3D substr(FILENOZIP,10,4)
while ( (getline < "\\test\\process.txt") > 0)
{
if (STORENUM =3D=3D $1)
{
DIRECTORY =3D $2
}
}
close("\\test\\stores.txt")
printf("Processing Store Number %s Date %s Direcotry %s
\n",STORENUM,FILEDATE,DIRECTORY)
printf("DEL workingtemp\\*.*\n") > "test.bat"
printf("WINZIP c:\\progra~1\\winzip\\wzunzip.exe -e %s.zip @list.txt
workingtemp\n",FILENOZIP) > "test.bat"
printf("RENAME workingtemp\\tnd.DBF workingtemp\\TD%s.dbf
\n",FILEDATESHRTYR) > "test.bat"
printf("RENAME workingtemp\\ite.DBF workingtemp\\IT%s.dbf
\n",FILEDATESHRTYR) > "test.bat"
printf("RENAME workingtemp\\Gsle.DBF workingtemp\\GS%s.dbf
\n",FILEDATESHRTYR) > "test.bat"
printf("wzzip.exe -m C:\\iFtpSvc\\info\\users\\download\\test
\\%s\\
%s.zip\n",DIRECTORY,FILEDATE) > "test.bat"
}
}
Post Follow-up to this messageOn Fri, 28 Mar 2008 10:08:26 -0700, tcdrake wrote:
>
It inserts yesterday's date between the existing basen name and the
estension.
Yes - it's a fragment to be used where needed. I don't like to do complete
batch files here.
>
> Well started over and simplified the code with everyone's assistance. I
> set it to unzip to a working directory, rename files, zip and move to
> the correct directory based on the location code. Then process the next
> zip. Here is it for everyone to see.
>
> BEGIN{
>
> while ( (getline < "stores.txt") > 0) { FILENOZIP =
> substr($0,1,(length($0) - 4)) FILEDATE = substr($0,1,8) FILEDATESHRTYR =
> substr($0,3,6)
> STORENUM = substr(FILENOZIP,10,4)
> while ( (getline < "\\test\\process.txt") > 0) {
> if (STORENUM == $1)
> {
> DIRECTORY = $2
> }
> }
> close("\\test\\stores.txt")
>
>
>
> printf("Processing Store Number %s Date %s Direcotry %s
> \n",STORENUM,FILEDATE,DIRECTORY)
> printf("DEL workingtemp\\*.*\n") > "test.bat" printf("WINZIP
> c:\\progra~1\\winzip\\wzunzip.exe -e %s.zip @list.txt
> workingtemp\n",FILENOZIP) > "test.bat"
>
>
>
> printf("RENAME workingtemp\\tnd.DBF workingtemp\\TD%s.dbf
> \n",FILEDATESHRTYR) > "test.bat"
> printf("RENAME workingtemp\\ite.DBF workingtemp\\IT%s.dbf
> \n",FILEDATESHRTYR) > "test.bat"
> printf("RENAME workingtemp\\Gsle.DBF workingtemp\\GS%s.dbf
> \n",FILEDATESHRTYR) > "test.bat"
>
> printf("wzzip.exe -m C:\\iFtpSvc\\info\\users\\download\\test
\\%s\\
> %s.zip\n",DIRECTORY,FILEDATE) > "test.bat"
>
>
>
>
> }
It's *much* simpler to leave the file names to the command processor and
use awk for the thing it does well - dealing with paths with backslashes
is not one of them (in part because of the ease of missing doubling one
that needs it and accidentally doubling one that doesn't).
--
T.E.D. (tdavis@mst.edu)
Post Follow-up to this messagetcdrake escreveu:
[snipped]
>
> Well started over and simplified the code with everyone's assistance.
> I set it to unzip to a working directory, rename files, zip and move
> to the correct directory based on the location code. Then process the
> next zip. Here is it for everyone to see.
Great.
>
> BEGIN{
>
> while ( (getline < "stores.txt") > 0)
[snipped]
Now, why do you use this construct intead of using the contents of the
script within the body of the while and call the script as:
C:\>awk -f script.awk stores.txt
HTH
--
Cesar Rabak
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.