DOS Baseball League Line Score Help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

DOS Baseball League Line Score Help

#1 Post by mjfoxtrot » 25 Jun 2014 19:23

Sorry for the length of this request, but I thought it would be best to explain my dilemma. I have a batch file that I cobbled together that does the basics of what I need for my DOS baseball league (yes, believe it or not, we have 30 guys who play 162 games each using an MS-DOS program.) But I could use some help to expand on my script's capability.

Basically, the script I have now can copy the top seven lines of each game's box score (these are standard .txt files) and put them into a separate .txt file. The script then further distills those seven lines down to a line score for the game. The result looks like this:

TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
Dragons 0 0 1 0 0 0 0 0 0 1 5 0 04-28-14
Redbirds 0 0 0 0 0 0 0 0 0 0 2 0 9:14pm

The advantage of this for me is that the above line score can import perfectly into Excel and I can do my record-keeping of game results quickly and efficiently.

BUT . . . right now, my script just does one game. I need the script to be able to process several games at once. Ideally, it would:

1. Scan all .txt files in a folder I specify AND its subfolders, and copy the top seven lines of each to an output text file;
2. It would write the output file so that each line score was prefaced by the folder name it is contained in, text file name, and finally the line score.

The folder names are all in the format of the two teams who played, with an @ symbol in between, i.e., ACA @ MID.

So, ultimately, you would end up with a .txt file that had something that looked like this:

ACA @ MID: GAME1.txt:
(line score line 1, no parens)
(line score line 2, no parens)
(line score line 3, no parens)
ACA @ MID: GAME2.txt:
(line score line 1, no parens)
(line score line 2, no parens)
(line score line 3, no parens)

. . . etc. etc.

I've included the script I have now that works to boil down the line score for one game. I am no expert by any means, so it probably is pretty clumsily written, but here it is:

Code: Select all

@setlocal enableextensions enabledelayedexpansion
@echo off
set input_file=GAME1.txt
cls
set /a out_num=1
set /a line1=1
set /a line2=2
set /a line3=3
set /a line4=4
set /a line5=5
set /a line6=6
set /a times=0

:start_find
cls
echo.
echo %out_num%
echo.
echo %line1%
echo %line2%
echo %line3%
echo %line4%
echo %line5%
echo %line6%
set lines=%line1% %line2% %line3% %line4% %line5% %line6%
set curr=1
for /f "delims=" %%a in ('type %input_file%') do (
for %%b in (!lines!) do (
set !curr!=curr
if !curr!==%%b echo %%a >>output_%out_num%.txt
)
set /a "curr = curr + 1"
)

findstr /v "ECHO BOXSCORE" output_1.txt > outfile.txt
del output_1.txt


Thanks for any help.

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

Re: DOS Baseball League Line Score Help

#2 Post by foxidrive » 26 Jun 2014 01:03

Can you provide a sample file and explain how it needs to produce the output file?

What is the purpose of this line?

Code: Select all

set !curr!=curr

mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

Re: DOS Baseball League Line Score Help

#3 Post by mjfoxtrot » 26 Jun 2014 02:10

Hi Foxidrive,

Here's a sample of a typical box score .txt file:

Code: Select all

************************************  BOXSCORE  *******************************


 TEAM       1  2  3  4  5  6  7  8  9   R  H  E                     DATE/TIME
Dragons    0  0  1  0  0  0  0  0  0   1  5  0                      04-28-14
Redbirds   0  0  0  0  0  0  0  0  0   0  2  0                        9:14pm
 
Bangor            Last
Dragons           Pos AB  R  H 2B 3B HR TB RBI  S HP BB SO SB CS  PO  A  E PB
 1 ANDRUS          SS  4  0  0  0  0  0  0   0  0  0  0  1  0  0   1  4  0  0
 2 ALTUVE          2B  4  0  1  0  0  0  1   0  0  0  0  1  0  0   1  2  0  0
 3 SEAGER          3B  4  0  0  0  0  0  0   0  0  0  0  1  0  0   0  0  0  0
 4 MORALES         1B  4  0  1  0  0  0  1   0  0  0  0  2  0  0   6  0  0  0
 5 LAGARES         LF  4  0  1  0  0  0  1   0  0  0  0  1  0  0   2  0  0  0
 6 MONTERO         C   3  0  0  0  0  0  0   0  0  1  0  1  0  0  11  0  0  0
 7 ROBINSON        CF  3  0  1  0  0  0  1   0  0  0  0  0  0  0   4  0  0  0
 8 BLANCO          RF  3  1  1  0  0  1  4   1  0  0  0  0  0  0   2  0  0  0
 9 BAILEY          P   3  0  0  0  0  0  0   0  0  0  0  1  0  0
   CISHEK          P   0  0  0  0  0  0  0   0  0  0  0  0  0  0
                     --- -- -- -- -- -- -- --- -- -- -- -- -- --
   Totals             32  1  5  0  0  1  8   1  0  0  0  8  0  0
 
-Pitchers-           IP   R  ER   H  2B  3B  HR  SO  BB WP HB BK
   BAILEY      W    8.1   0   0   2   0   0   0   9   1  0  0  0   0  0  0  0
   CISHEK      S    0.2   0   0   0   0   0   0   1   0  0  0  0   0  0  0  0
                   ---- --- --- --- --- --- --- --- --- -- -- --  -- -- -- --
   Totals           9.0   0   0   2   0   0   0  10   1  0  0  0  27  6  0  0
 
  INJURIES:
 
 
Aliso Viejo       Last
Redbirds          Pos AB  R  H 2B 3B HR TB RBI  S HP BB SO SB CS  PO  A  E PB
 1 YELICH          CF  4  0  1  0  0  0  1   0  0  0  0  1  0  0   7  0  0  0
 2 KIPNIS          2B  4  0  0  0  0  0  0   0  0  0  0  2  0  0   0  2  0  0
 3 SANTANA         C   4  0  0  0  0  0  0   0  0  0  0  1  0  0   9  0  0  0
 4 CRUZ            RF  3  0  0  0  0  0  0   0  0  0  0  0  0  0   0  0  0  0
 5 ADAMS           1B  3  0  1  0  0  0  1   0  0  0  0  2  0  0   8  1  0  0
 6 ALVAREZ         3B  3  0  0  0  0  0  0   0  0  0  0  0  0  0   0  0  0  0
 7 COZART          SS  3  0  0  0  0  0  0   0  0  0  0  0  0  0   0  4  0  0
 8 DUDA            LF  3  0  0  0  0  0  0   0  0  0  0  3  0  0   2  0  0  0
 9 CORBIN          P   2  0  0  0  0  0  0   0  0  0  0  1  0  0
   YOUNG           PH  0  0  0  0  0  0  0   0  0  0  1  0  0  0
                     --- -- -- -- -- -- -- --- -- -- -- -- -- --
   Totals             29  0  2  0  0  0  2   0  0  0  1 10  0  0
 
-Pitchers-           IP   R  ER   H  2B  3B  HR  SO  BB WP HB BK
   CORBIN      L    9.0   1   1   5   0   0   1   8   0  0  1  0   1  1  0  0
                   ---- --- --- --- --- --- --- --- --- -- -- --  -- -- -- --
   Totals           9.0   1   1   5   0   0   1   8   0  0  1  0  27  8  0  0
 
  INJURIES:
 

*******************************   END OF BOXSCORE  ****************************


It's a fixed-width text file, so it doesn't cut-and-paste well to the forum reply I am posting, but I think you can get the drift of what it looks like. Essentially, the lines I need are these:

Code: Select all

TEAM       1  2  3  4  5  6  7  8  9   R  H  E                     DATE/TIME
Dragons    0  0  1  0  0  0  0  0  0   1  5  0                      04-28-14
Redbirds   0  0  0  0  0  0  0  0  0   0  2  0                        9:14pm


The script I provided does that for a single file. As for the "set !curr!=curr" line . . . my bad, that was some leftover code that I had not deleted. That line is not necessary for the functioning of the script. I guess I was just lucky that it was not screwing things up.

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

Re: DOS Baseball League Line Score Help

#4 Post by foxidrive » 26 Jun 2014 02:22

Is your file correct in the code tags above?

I get a different result in the outfile.txt

Code: Select all

 TEAM       1  2  3  4  5  6  7  8  9   R  H  E                     DATE/TIME 
Dragons    0  0  1  0  0  0  0  0  0   1  5  0                      04-28-14
Redbirds   0  0  0  0  0  0  0  0  0   0  2  0                        9:14pm
Bangor            Last
Dragons           Pos AB  R  H 2B 3B HR TB RBI  S HP BB SO SB CS  PO  A  E PB


Where does the GAME1.txt and GAME2.txt come from in the first post?

mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

Re: DOS Baseball League Line Score Help

#5 Post by mjfoxtrot » 26 Jun 2014 03:33

The code tags are NOT correct . . . for some reason, they are not including the first two lines, and hence, that is why you are getting different output from the script. The code tags are excluding the first few lines, namely, this:

************************************ BOXSCORE *******************************


. . . so that's a blank line, then the BOXSCORE line, and two blank lines after it. The first seven lines should be comprised of the lines you see above, and then three lines of line score information, i.e., this:

TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
Dragons 0 0 1 0 0 0 0 0 0 1 5 0 04-28-14
Redbirds 0 0 0 0 0 0 0 0 0 0 2 0 9:14pm

As for where the GAME1.txt and GAME2.txt references come from: let me explain the directory structure of the folder that the script would be examining.

It is essentially like this:

C:\1DOS\FACTORY\ is the parent directory.

Inside it are folders that contain each series that our league played on a particular day. For instance:

C:\1DOS\FACTORY\MID @ ACA\ . . . is a folder that signifies that the team with initials MID (short for Mid-Atlantic) was the visiting team and that ACA (short for Acadia) was the home team (signified by the @ in front of ACA.)

And inside the C:\1DOS\FACTORY\MID @ ACA\ folder, there will be either three or four .txt files, all named GAME1.txt, GAME2.txt, GAME3.txt, and if a fourth game was played between the two teams, GAME4.txt. For sake of simplicity, let's call each of these folders a SERIES folder.

So basically, the C:\1DOS\FACTORY\ folder will have many SERIES folders, each containing three or four text files each. They will ALWAYS be named GAME1.txt, GAME2.TXT, GAME3.txt, and will fairly often have a fourth file named GAME4.txt (our league plays three- and four-game series, with the four-game series being more prevalent.)

Since my intention is to update the league scores nightly, and a typical day in the league sees between two and 10 series played, the C:\1DOS\FACTORY\ folder will typically have between two and 10 SERIES folders on each night. So, my goal is to run the script on them, and get my handy-dandy text file that shows all the line scores for the games that I can import into Excel. Let's call this file SCORES.txt.

After talking this through, I actually think the best way to have this file is to have each line prefaced by the SERIES folder, and the text file name from whence the line score came. In other words, the output would be like I said in my first post, but with this modification:

MID @ ACA: GAME1.TXT: (line 1 of linescore)
MID @ ACA: GAME2.TXT: (line 2 of linescore)
MID @ ACA: GAME3.TXT: (line 3 of linescore)
. . . and so on, for each of the series folders in C:\1DOS\FACTORY\

Hope that helps. I know it's a lot to swallow and if it is not practical to do this, please don't feel any burden. You already helped me out a lot with my request a few weeks ago.

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

Re: DOS Baseball League Line Score Help

#6 Post by foxidrive » 26 Jun 2014 03:49

See if this gives you what you need: it will write the score.txt on your desktop:

Code: Select all

@echo off
pushd "C:\1DOS\FACTORY\"
for /d %%a in (*) do (
 pushd "%%a"
   for %%b in (game?.txt) do (
      for /f "delims=" %%c in (' findstr /r "[0-9]-[0-9] [0-9]:[0-9] DATE.TIME"  ^< "%%b" ') do >>"%userprofile%\desktop\score.txt" echo %%~nxa: %%b: %%c
   )
 popd
)
popd
echo done
pause

mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

Re: DOS Baseball League Line Score Help

#7 Post by mjfoxtrot » 26 Jun 2014 04:11

Holy Smokes! That worked PERFECT! I plopped a bunch of series folders into the parent directory and let your script have at them. It immediately produced exactly what I was looking for:

IND @ BCB: GAME1.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
IND @ BCB: GAME1.TXT: Colts 0 0 0 0 1 0 0 4 0 5 8 2 05-01-14
IND @ BCB: GAME1.TXT: Bigfoots 2 0 0 0 0 1 0 0 0 3 4 0 9:59pm
IND @ BCB: GAME2.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
IND @ BCB: GAME2.TXT: Colts 0 2 0 1 1 1 3 1 1 10 16 0 05-01-14
IND @ BCB: GAME2.TXT: Bigfoots 0 0 0 0 2 1 0 0 0 3 11 0 10:08pm
IND @ BCB: GAME3.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
IND @ BCB: GAME3.TXT: Colts 0 0 2 0 4 0 1 0 0 7 14 0 05-01-14
IND @ BCB: GAME3.TXT: Bigfoots 2 0 1 0 0 0 0 1 0 4 9 0 10:18pm
MED @ ACA: GAME1.TXT: TEAM 1 2 3 4 5 6 7 8 9 10 11 12 13 R H E DATE/TIME
MED @ ACA: GAME1.TXT: Lakers 0 0 0 0 0 1 1 0 0 0 0 0 1 3 9 2 05-05-14
MED @ ACA: GAME1.TXT: Black Fly 0 0 0 1 0 1 0 0 0 0 0 0 0 2 9 3 8:06pm
MED @ ACA: GAME2.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
MED @ ACA: GAME2.TXT: Lakers 0 0 0 1 0 0 0 1 0 2 7 1 05-05-14
MED @ ACA: GAME2.TXT: Black Fly 0 1 1 0 1 0 2 0 0 5 7 2 8:25pm
MED @ ACA: GAME3.TXT: TEAM 1 2 3 4 5 6 7 8 9 10 R H E DATE/TIME
MED @ ACA: GAME3.TXT: Lakers 0 0 0 6 0 1 0 0 0 1 8 11 1 05-05-14
MED @ ACA: GAME3.TXT: Black Fly 0 1 0 0 1 5 0 0 0 0 7 12 1 8:37pm
MED @ ACA: GAME4.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
MED @ ACA: GAME4.TXT: Lakers 0 0 1 0 0 2 0 3 0 6 10 0 05-05-14
MED @ ACA: GAME4.TXT: Black Fly 0 0 0 0 0 0 0 0 0 0 7 0 8:51pm
NEW @ ACA: GAME1.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
NEW @ ACA: GAME1.TXT: Buffaloes 1 1 0 0 0 0 0 0 0 2 8 2 05-29-14
NEW @ ACA: GAME1.TXT: Black Fly 0 4 1 2 0 0 1 7 0 15 19 2 8:04pm
NEW @ ACA: GAME2.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
NEW @ ACA: GAME2.TXT: Buffaloes 2 0 1 0 1 0 1 0 5 10 17 0 05-29-14
NEW @ ACA: GAME2.TXT: Black Fly 0 0 0 0 0 0 0 0 1 1 5 1 8:13pm
NEW @ ACA: GAME3.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
NEW @ ACA: GAME3.TXT: Buffaloes 0 0 0 2 0 0 0 0 0 2 4 1 05-29-14
NEW @ ACA: GAME3.TXT: Black Fly 0 0 0 3 2 6 0 1 0 12 13 1 8:20pm
ROS @ ACA: GAME1.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
ROS @ ACA: GAME1.TXT: Paranorms 0 0 0 0 0 0 0 0 0 0 5 1 05-21-14
ROS @ ACA: GAME1.TXT: Black Fly 0 0 0 0 0 0 3 0 0 3 4 0 8:45pm
ROS @ ACA: GAME2.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
ROS @ ACA: GAME2.TXT: Paranorms 0 0 0 0 0 0 0 3 0 3 9 1 05-21-14
ROS @ ACA: GAME2.TXT: Black Fly 0 6 1 0 3 0 0 0 0 10 15 1 9:14pm
ROS @ ACA: GAME3.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
ROS @ ACA: GAME3.TXT: Paranorms 0 0 1 5 0 0 0 1 3 10 10 1 05-21-14
ROS @ ACA: GAME3.TXT: Black Fly 1 0 0 0 0 0 0 0 0 1 5 0 9:22pm
ROS @ ACA: GAME4.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
ROS @ ACA: GAME4.TXT: Paranorms 0 0 1 1 0 0 0 1 2 5 11 1 05-21-14
ROS @ ACA: GAME4.TXT: Black Fly 0 0 0 1 0 0 0 0 1 2 10 1 9:31pm
SUN @ BCB: GAME1.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
SUN @ BCB: GAME1.TXT: Brawlers 1 0 1 0 0 0 0 2 3 7 6 0 05-18-14
SUN @ BCB: GAME1.TXT: Bigfoots 0 1 0 0 0 0 0 2 0 3 10 0 7:40pm
SUN @ BCB: GAME2.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
SUN @ BCB: GAME2.TXT: Brawlers 2 1 2 0 0 0 0 0 0 5 6 0 05-18-14
SUN @ BCB: GAME2.TXT: Bigfoots 2 0 0 1 0 0 0 0 0 3 7 1 7:51pm
SUN @ BCB: GAME3.TXT: TEAM 1 2 3 4 5 6 7 8 R H E DATE/TIME
SUN @ BCB: GAME3.TXT: Brawlers 2 0 1 0 1 1 0 0 5 11 1 05-18-14
SUN @ BCB: GAME3.TXT: Bigfoots 0 0 0 0 0 0 0 0 0 1 0 8:01pm
SUN @ BCB: GAME4.TXT: TEAM 1 2 3 4 5 6 7 8 9 R H E DATE/TIME
SUN @ BCB: GAME4.TXT: Brawlers 0 2 0 0 0 0 0 1 0 3 5 1 05-18-14
SUN @ BCB: GAME4.TXT: Bigfoots 0 0 0 2 0 0 0 0 0 2 4 1 8:09pm

I told you two weeks ago that I was writing you into my will. I will now also make arrangements for you to have extensive use of the family yacht on weekends ;)

Thank you very much, Foxidrive. Your skills are quite remarkable. If you ever get the urge to play in a DOS baseball league, I'll find you a spot :)

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

Re: DOS Baseball League Line Score Help

#8 Post by foxidrive » 26 Jun 2014 08:57

mjfoxtrot wrote:I told you two weeks ago that I was writing you into my will. I will now also make arrangements for you to have extensive use of the family yacht on weekends ;)


hehe I'll have to arrange a time share so the I can sail it back to The Land Down Under. ;)

Glad to see it works.

mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

Re: DOS Baseball League Line Score Help

#9 Post by mjfoxtrot » 26 Jun 2014 11:21

The land down under, eh? In that case, my DOS baseball league won't have any appeal. I'll get to work on starting up a DOS rugby league ;)

Post Reply