Page 1 of 1

summary from multiple text files in folder

Posted: 06 Jul 2012 11:20
by DingDang
I have multiple text files in folder in which there is row start from "Total"
I want batch file which get all row of file start from Total in one file also start from file name
e.g
file name in folder c:\text\ file name 1.txt, 2.txt,3.txt.....so on

result required in seprate file which auto save as summary.txt in same foleder.

file name total
1.txt 12121.00
2.txt 23232.00
3.txt 454545.00

Pls help

Re: summary from multiple text files in folder

Posted: 06 Jul 2012 17:36
by Aacini

Code: Select all

@echo off
( for %%a in (*.txt) do (
   for /F "tokens=2" %%b in ('findstr "Total" "%%a"') do echo %%a  %%b
) ) > summary.tmp
ren summary.tmp summary.txt

Re: summary from multiple text files in folder

Posted: 08 Jul 2012 09:40
by DingDang
Gre8..Thanks a lot for code.

but, one more help required in summary file entire row not copying. txt file contain below data which start from Total.

TOTAL: 71 15,74,786.00 97 1,14,06,129.35
TOTAL: 3 15,80,696.70 1,262 81,31,483.87

it should copy entire row. pls help
requried details in summary file should as below

1.txt TOTAL: 71 15,74,786.00 97 1,14,06,129.35
2.TXT TOTAL: 3 15,80,696.70 1,262 81,31,483.87

Re: summary from multiple text files in folder

Posted: 08 Jul 2012 11:41
by foxidrive
This returns the text below it. Is that any good?

Code: Select all

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


1.txt:TOTAL: 71 15,74,786.00 97 1,14,06,129.35
2.txt:TOTAL: 3 15,80,696.70 1,262 81,31,483.87

Re: summary from multiple text files in folder

Posted: 09 Jul 2012 10:08
by DingDang
Dear foxidrive.

u r simply the great...its work.

Thanks a lot. :)