Batch file for parsing names out of text files
Posted: 07 Apr 2015 01:55
I've had wonderful help on this board before and I am hoping someone might have a solution for my latest quandary. Please bear with my long-winded explanation, as I want to make sure that I'm including all relevant information.
My goal: a batch file that will go through the box scores generated by my MS-DOS baseball program and generate a text file that contains the name of the starting pitchers for each game.
The box scores are simple .txt files. They are each in subdirectories like this:
C:\1DOS\Factory\BAN @ IND\GAME1.TXT
C:\1DOS\Factory\BAN @ IND\GAME2.TXT
C:\1DOS\Factory\BAN @ IND\GAME3.TXT
C:\1DOS\Factory\BAN @ IND\GAME4.TXT
C:\1DOS\Factory\MID @ ACA\GAME1.TXT
. . . and so on and so on. The number of subdirectories may vary from three or four to as many as 34.
What I need is for the batch file to read each text file in the subdirectories and find the starting pitchers. There is a pattern that I think would make this possible. The starting pitcher is always listed on the line immediately following this line:
-Pitchers- IP R ER H 2B 3B HR SO BB WP HB BK
. . . the next line contains the starting pitcher's name and his stats, like so:
PORCELLO L 6.0 2 2 3 1 0 0 2 2 0 0 0 0 2 0 0
What I am hoping for is that the batch file would output all the lines containing the starting pitchers and their stats to a separate text file. So it would be like this:
PORCELLO L 6.0 2 2 3 1 0 0 2 2 0 0 0 0 2 0 0
HERNANDEZ W 7.1 1 1 1 0 0 1 9 1 0 0 0 0 0 0 0
GIBSON L 5.1 5 5 11 5 0 0 5 0 0 0 0 1 1 0 0
TEHERAN W 7.0 1 1 4 1 0 0 8 1 0 0 0 0 0 0 0
. . . and so on and so on. Ideally, each line would be prefaced by the name of text file and the subdirectory that the text file resides in, i.e.,
BAN @ IND: GAME1.TXT: PORCELLO L 6.0 2 2 3 1 0 0 2 2 0 0 0 0 2 0 0
BAN @ IND: GAME1.TXT: HERNANDEZ W 7.1 1 1 1 0 0 1 9 1 0 0 0 0 0 0 0
BAN @ IND: GAME2.TXT: GIBSON L 5.1 5 5 11 5 0 0 5 0 0 0 0 1 1 0 0
BAN @ IND: GAME2:TXT: TEHERAN W 7.0 1 1 4 1 0 0 8 1 0 0 0 0 0 0 0
If it helps, I have included the full text of one of the box scores:
************************************ BOXSCORE *******************************
TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
Dragons 0 0 0 0 0 1 0 0 2 3 6 0 04-06-15
Colts 0 0 0 2 2 1 4 0 0 9 16 0 9:21pm
Bangor Last
Dragons Pos AB R H 2B 3B HR TB RBI S HP BB SO SB CS PO A E PB
1 DYSON LF 2 1 1 0 0 0 1 0 0 0 2 0 1 0 0 0 0 0
2 LAGARES CF 4 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0
3 VOTTO 1B 4 1 1 0 0 1 4 1 0 0 0 0 0 0 7 3 0 0
4 SEAGER 3B 3 1 1 1 0 0 2 1 0 0 1 0 0 0 1 1 0 0
5 LeMAHIEU 2B 4 0 3 0 1 0 5 1 0 0 0 0 0 0 2 1 0 0
6 MONTERO C 4 0 0 0 0 0 0 0 0 0 0 1 0 0 9 1 0 0
7 ANDRUS SS 4 0 0 0 0 0 0 0 0 0 0 2 0 0 1 2 0 0
8 BLANCO RF 4 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0
9 GIBSON P 2 0 0 0 0 0 0 0 0 0 0 2 0 0
VEAL P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PARRA P 1 0 0 0 0 0 0 0 0 0 0 0 0 0
--- -- -- -- -- -- -- --- -- -- -- -- -- --
Totals 32 3 6 1 1 1 12 3 0 0 3 8 1 0
-Pitchers- IP R ER H 2B 3B HR SO BB WP HB BK
GIBSON L 5.1 5 5 11 5 0 0 5 0 0 0 0 1 1 0 0
VEAL 1.1 4 4 4 0 0 0 2 1 1 0 0 1 0 0 0
PARRA 1.1 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0
---- --- --- --- --- --- --- --- --- -- -- -- -- -- -- --
Totals 8.0 9 9 16 5 0 0 9 1 1 0 0 24 10 0 0
INJURIES:
Indy Last
Colts Pos AB R H 2B 3B HR TB RBI S HP BB SO SB CS PO A E PB
1 GORDON 2B 4 3 2 1 0 0 3 1 0 0 1 1 1 0 2 4 0 0
2 DE AZA RF 5 1 3 0 0 0 3 2 0 0 0 1 0 1 1 0 0 0
3 JONES CF 4 0 0 0 0 0 0 0 0 0 0 3 0 0 6 0 0 0
4 LONGORIA 3B 4 1 1 0 0 0 1 1 0 0 0 2 0 0 2 1 0 0
5 DAVIS 1B 1 0 1 1 0 0 2 0 0 0 0 0 0 0 2 0 0 0
GIMENEZ 1B 3 2 3 2 0 0 5 2 0 0 0 0 0 0 3 0 0 0
6 SEGURA SS 4 0 2 1 0 0 3 2 0 0 0 0 0 0 1 0 0 0
HUDSON P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MATUSZ P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COLEMAN P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
7 PEREZ C 4 0 2 0 0 0 2 1 0 0 0 0 0 0 8 0 0 0
8 BROWN LF 4 1 1 0 0 0 1 0 0 0 0 0 1 0 2 0 0 0
9 TEHERAN P 2 0 0 0 0 0 0 0 0 0 0 1 0 0
GARCIA SS 2 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0
--- -- -- -- -- -- -- --- -- -- -- -- -- --
Totals 37 9 16 5 0 0 21 9 0 0 1 9 2 1
-Pitchers- IP R ER H 2B 3B HR SO BB WP HB BK
TEHERAN W 7.0 1 1 4 1 0 0 8 1 0 0 0 0 0 0 0
HUDSON 1.0 2 2 2 0 1 1 0 2 0 0 0 0 0 0 0
MATUSZ 0.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COLEMAN 0.2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
---- --- --- --- --- --- --- --- --- -- -- -- -- -- -- --
Totals 9.0 3 3 6 1 1 1 8 3 0 0 0 27 6 0 0
INJURIES: DAVIS(1)
******************************* END OF BOXSCORE ****************************
My goal: a batch file that will go through the box scores generated by my MS-DOS baseball program and generate a text file that contains the name of the starting pitchers for each game.
The box scores are simple .txt files. They are each in subdirectories like this:
C:\1DOS\Factory\BAN @ IND\GAME1.TXT
C:\1DOS\Factory\BAN @ IND\GAME2.TXT
C:\1DOS\Factory\BAN @ IND\GAME3.TXT
C:\1DOS\Factory\BAN @ IND\GAME4.TXT
C:\1DOS\Factory\MID @ ACA\GAME1.TXT
. . . and so on and so on. The number of subdirectories may vary from three or four to as many as 34.
What I need is for the batch file to read each text file in the subdirectories and find the starting pitchers. There is a pattern that I think would make this possible. The starting pitcher is always listed on the line immediately following this line:
-Pitchers- IP R ER H 2B 3B HR SO BB WP HB BK
. . . the next line contains the starting pitcher's name and his stats, like so:
PORCELLO L 6.0 2 2 3 1 0 0 2 2 0 0 0 0 2 0 0
What I am hoping for is that the batch file would output all the lines containing the starting pitchers and their stats to a separate text file. So it would be like this:
PORCELLO L 6.0 2 2 3 1 0 0 2 2 0 0 0 0 2 0 0
HERNANDEZ W 7.1 1 1 1 0 0 1 9 1 0 0 0 0 0 0 0
GIBSON L 5.1 5 5 11 5 0 0 5 0 0 0 0 1 1 0 0
TEHERAN W 7.0 1 1 4 1 0 0 8 1 0 0 0 0 0 0 0
. . . and so on and so on. Ideally, each line would be prefaced by the name of text file and the subdirectory that the text file resides in, i.e.,
BAN @ IND: GAME1.TXT: PORCELLO L 6.0 2 2 3 1 0 0 2 2 0 0 0 0 2 0 0
BAN @ IND: GAME1.TXT: HERNANDEZ W 7.1 1 1 1 0 0 1 9 1 0 0 0 0 0 0 0
BAN @ IND: GAME2.TXT: GIBSON L 5.1 5 5 11 5 0 0 5 0 0 0 0 1 1 0 0
BAN @ IND: GAME2:TXT: TEHERAN W 7.0 1 1 4 1 0 0 8 1 0 0 0 0 0 0 0
If it helps, I have included the full text of one of the box scores:
************************************ BOXSCORE *******************************
TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
Dragons 0 0 0 0 0 1 0 0 2 3 6 0 04-06-15
Colts 0 0 0 2 2 1 4 0 0 9 16 0 9:21pm
Bangor Last
Dragons Pos AB R H 2B 3B HR TB RBI S HP BB SO SB CS PO A E PB
1 DYSON LF 2 1 1 0 0 0 1 0 0 0 2 0 1 0 0 0 0 0
2 LAGARES CF 4 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0
3 VOTTO 1B 4 1 1 0 0 1 4 1 0 0 0 0 0 0 7 3 0 0
4 SEAGER 3B 3 1 1 1 0 0 2 1 0 0 1 0 0 0 1 1 0 0
5 LeMAHIEU 2B 4 0 3 0 1 0 5 1 0 0 0 0 0 0 2 1 0 0
6 MONTERO C 4 0 0 0 0 0 0 0 0 0 0 1 0 0 9 1 0 0
7 ANDRUS SS 4 0 0 0 0 0 0 0 0 0 0 2 0 0 1 2 0 0
8 BLANCO RF 4 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0
9 GIBSON P 2 0 0 0 0 0 0 0 0 0 0 2 0 0
VEAL P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PARRA P 1 0 0 0 0 0 0 0 0 0 0 0 0 0
--- -- -- -- -- -- -- --- -- -- -- -- -- --
Totals 32 3 6 1 1 1 12 3 0 0 3 8 1 0
-Pitchers- IP R ER H 2B 3B HR SO BB WP HB BK
GIBSON L 5.1 5 5 11 5 0 0 5 0 0 0 0 1 1 0 0
VEAL 1.1 4 4 4 0 0 0 2 1 1 0 0 1 0 0 0
PARRA 1.1 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0
---- --- --- --- --- --- --- --- --- -- -- -- -- -- -- --
Totals 8.0 9 9 16 5 0 0 9 1 1 0 0 24 10 0 0
INJURIES:
Indy Last
Colts Pos AB R H 2B 3B HR TB RBI S HP BB SO SB CS PO A E PB
1 GORDON 2B 4 3 2 1 0 0 3 1 0 0 1 1 1 0 2 4 0 0
2 DE AZA RF 5 1 3 0 0 0 3 2 0 0 0 1 0 1 1 0 0 0
3 JONES CF 4 0 0 0 0 0 0 0 0 0 0 3 0 0 6 0 0 0
4 LONGORIA 3B 4 1 1 0 0 0 1 1 0 0 0 2 0 0 2 1 0 0
5 DAVIS 1B 1 0 1 1 0 0 2 0 0 0 0 0 0 0 2 0 0 0
GIMENEZ 1B 3 2 3 2 0 0 5 2 0 0 0 0 0 0 3 0 0 0
6 SEGURA SS 4 0 2 1 0 0 3 2 0 0 0 0 0 0 1 0 0 0
HUDSON P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MATUSZ P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COLEMAN P 0 0 0 0 0 0 0 0 0 0 0 0 0 0
7 PEREZ C 4 0 2 0 0 0 2 1 0 0 0 0 0 0 8 0 0 0
8 BROWN LF 4 1 1 0 0 0 1 0 0 0 0 0 1 0 2 0 0 0
9 TEHERAN P 2 0 0 0 0 0 0 0 0 0 0 1 0 0
GARCIA SS 2 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0
--- -- -- -- -- -- -- --- -- -- -- -- -- --
Totals 37 9 16 5 0 0 21 9 0 0 1 9 2 1
-Pitchers- IP R ER H 2B 3B HR SO BB WP HB BK
TEHERAN W 7.0 1 1 4 1 0 0 8 1 0 0 0 0 0 0 0
HUDSON 1.0 2 2 2 0 1 1 0 2 0 0 0 0 0 0 0
MATUSZ 0.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COLEMAN 0.2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
---- --- --- --- --- --- --- --- --- -- -- -- -- -- -- --
Totals 9.0 3 3 6 1 1 1 8 3 0 0 0 27 6 0 0
INJURIES: DAVIS(1)
******************************* END OF BOXSCORE ****************************