get the data from multiple text in Zip file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

get the data from multiple text in Zip file

#1 Post by DingDang » 15 Jul 2012 10:22

Hi,

I have multiple zip file date wise in folder (like- 01072012.zip..02072012.zip..03072012.zip ) in which there is one text file with same file name in all zip file( cr09.txt ).if i exact all zip file in folder due to same file name in all zip file its got override.

i want bat file which give me particular row start with TOTAL form each text file (cr09.txt) from all zip files in separate file with file name summary.txt in same folder.

i got the below code by foxidrive but this apply only all txt file in folder.

@echo off
findstr /i "^TOTAL:" *.txt >summary.txt

Requred result as below

file name total
01072012.zip Total :

Pls help

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get the data from multiple text in Zip file

#2 Post by foxidrive » 15 Jul 2012 10:44

This should be a start. It requires UNZIP.EXE or another program to unzip the ZIP files.


Code: Select all

@echo off
for %%a in (*.zip) do (
del cr09.txt 2>nul
unzip "%%a"
findstr /i /s "^TOTAL:" cr09.txt >>summary.txt
del cr09.txt 2>nul
)

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

Re: get the data from multiple text in Zip file

#3 Post by DingDang » 15 Jul 2012 11:13

Sir,

Thanks for your prompt reply.. have copy unzip.exe in folder but its showing

"Archive: 1.zip
replace1/cr09.txt? ( y-yes),(N-no),(A-all),(R-rename): "

for each file

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get the data from multiple text in Zip file

#4 Post by foxidrive » 15 Jul 2012 12:11

It seems to be creating directories, so try the following with the switches in unzip.

Code: Select all

@echo off
for %%a in (*.zip) do (
del cr09.txt 2>nul
unzip -jo "%%a"
findstr /i /s "^TOTAL:" cr09.txt >>summary.txt
del cr09.txt 2>nul
)

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

Re: get the data from multiple text in Zip file

#5 Post by DingDang » 15 Jul 2012 12:24

Sir,

not asking for replace file now. but its create only summary file ( 0 kb) without any data.
not geting any data from txt file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get the data from multiple text in Zip file

#6 Post by foxidrive » 15 Jul 2012 12:38

Two things have to be checked.

A) that there is a cr09.txt file in the zip file
B) that it contains TOTAL: in the first column.

Try this version and when it pauses, don't press a key but examine the folder for a cr09.txt file and check the contents.
Then you can press a key and check the next file in the same way.

Before the pause it should list the text files in the folder for you.

Code: Select all

@echo off
for %%a in (*.zip) do (
del cr09.txt 2>nul
unzip -jo "%%a"
dir *.txt
pause
findstr /i /s "^TOTAL:" cr09.txt >>summary.txt
del cr09.txt 2>nul
)

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

Re: get the data from multiple text in Zip file

#7 Post by DingDang » 15 Jul 2012 20:52

Sir,

still not work,

A) that there is a cr09.txt file in the zip file
: in zip file there is folder in which cr09.txt file exist.

B) that it contains TOTAL: in the first column.
: i think contains TOTAL: is not in first column., copy raw from cr09.txt below for your ref.
TOTAL: start from column 8.

TOTAL: 5 15,85,600.70 1,268 81,31,473.81

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get the data from multiple text in Zip file

#8 Post by foxidrive » 16 Jul 2012 06:47

Try this. It now looks for Total: in any column.

Code: Select all

@echo off
for %%a in (*.zip) do (
del cr09.txt 2>nul
unzip -jo "%%a"
findstr /i /s "TOTAL:" cr09.txt >>summary.txt
del cr09.txt 2>nul
)

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

Re: get the data from multiple text in Zip file

#9 Post by DingDang » 16 Jul 2012 10:02

YES!! perfect.. its work..
Thanks a lot :D .

But as I mentioned in my first post. is it possible to get zip file name in summary instead of CR09.TXT.

In output file getting below data which i required. but due to same file name in all zip file it won't give me date which is mentioned in zip file name.

zip file name will be date wise like ( 01072012.zip, 02072012.zip, 03072012.zip.... )required zip file name and total of cr09.txt of that perticuler zip file in summary.

Thank u once again ...

CR09.TXT: TOTAL: 3
CR09.TXT: TOTAL: 4
CR09.TXT: TOTAL: 5
CR09.TXT: TOTAL: 6
CR09.TXT: TOTAL: 7
CR09.TXT: TOTAL: 8
CR09.TXT: TOTAL: 9
CR09.TXT: TOTAL: 10

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get the data from multiple text in Zip file

#10 Post by foxidrive » 16 Jul 2012 10:37

Try this:

Code: Select all

@echo off
for %%a in (*.zip) do (
del cr09.txt 2>nul
unzip -jo "%%a"
for /f "delims=" %%b in ('findstr /i "TOTAL:" cr09.txt') do >>summary.txt echo %%a: %%b
del cr09.txt 2>nul
)

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

Re: get the data from multiple text in Zip file

#11 Post by DingDang » 16 Jul 2012 11:13

Sir,

perfect what i want....u r simply the greee8..many thanks .

Post Reply