-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpgn_extract6.sh
55 lines (38 loc) · 1.12 KB
/
pgn_extract6.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
49
50
51
52
53
54
#!/usr/bin/env bash
# A blank line is a line containing (only) 0 or more whitespaces
regex_blank="^[[:space:]]*$"
# reads through the initial game data of PGN data and returns
# success if any line matched the regex in the first argument
function filter_game()
{
# ret will be returned by the function - initially assume failure
local ret=1
while read -r line
do
# Set ret to 0 if the line matches the filter
[[ $line =~ $1 ]] && ret=0
# FOR TESTING: Print the line
[[ $line =~ $1 ]] && echo "$line"
# Break if line is blank
[[ $line =~ $regex_blank ]] && break
done
return $ret
}
# Read all the lines of the PGN move list and concatenate them into the variable moves
function read_moves()
{
# Clear the moves variable
moves=''
while read -r line
do
# Quit if line is blank
[[ $line =~ $regex_blank ]] && return 0
# Append the line to moves with space in between
moves="${moves} ${line}"
done
# Quit with failure return code here since read could not get another line
return 1
}
filter_game '\[Result "(1-0|0-1)"\]'
read_moves
echo "$moves"