-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_rs_events.sh
executable file
·48 lines (46 loc) · 1.34 KB
/
parse_rs_events.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# Parse retrosheet event files
dirs=(~/retrosheet/event/asg
~/retrosheet/event/post
~/retrosheet/event/regular)
outdir=~/retrosheet-csv/csv
touch team
for dir in ${dirs[@]}
do
for file in $dir/*
do
if [[ $file =~ EV.$|ED.$ ]]
then
echo "Processing ${file##*/}"
/usr/local/bin/cwgame -q -f 0-83 -x 0-94 -n $file > $outdir/${file##*/}.${dir##*/}.game.csv
/usr/local/bin/cwevent -q -f 0-96 -x 0-62 -n $file > $outdir/${file##*/}.${dir##*/}.event.csv
/usr/local/bin/cwcomment -q -n -f 0-2 $file > $outdir/${file##*/}.${dir##*/}.comment.csv
/usr/local/bin/cwsub -q -n $file > $outdir/${file##*/}.${dir##*/}.sub.csv
/usr/local/bin/cwdaily -q -n $file > $outdir/${file##*/}.${dir##*/}.daily.csv
elif [[ $file =~ EB.$ ]]
then
echo "Processing ${file##*/}"
/usr/local/bin/cwdaily -q -n $file > $outdir/${file##*/}.${dir##*/}.daily.csv
else
continue
fi
done
done
rm team
# Append filename and line number to csv records
for file in csv/*.csv
do
echo "Appending ${file##*/}"
gawk -i inplace '
function basename(file) {
sub(".*/", "", file)
return file
}
{
{ gsub(/\n/, ",") }
if (FNR==1)
{ print $0 ",\"" "FILENAME_TX" "\",\"" "LINE_NUMBER_CT" "\"" }
else { print $0 ",\"" basename(FILENAME) "\"," FNR }
}
' $file
done