I’m very new to bash and i tried matching a pattern inside a text.
The goal was to divide a pgn file with a lot of chess games to a lot of files, each of them containing one game.
I tried this command:
if echo "$line" | grep -P ".*(1-0|0-1|1/2-1/2)$
but it doesn’t match my text, here is an example of it with exacly two games:
[Event "57th Capablanca Mem"]
[Site "Havana CUB"]
[Date "2024.05.03"]
[Round "1"]
[White "Andersen,Mad"]
[Black "Quesada Perez,Luis Ernesto"]
[Result "0-1"]
[WhiteElo "2598"]
[BlackElo "2567"]
[EventDate "2024.05.03"]
[ECO "C65"]
1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. d3 Bc5 5. c3 d5 6. Nbd2 dxe4 7. dxe4 O-O
8. O-O a5 9. Qc2 Qe7 10. a4 Rd8 11. h3 Nb8 12. Re1 Nbd7 13. Nf1 Nf8 14. Ng3
h6 15. Bc4 c6 16. Nh4 Be6 17. Nhf5 Qc7 18. Qe2 Bxc4 19. Qxc4 Ne6 20. Qe2
Rd7 21. Qf3 Qd8 22. Be3 Bxe3 23. Nxe3 Ng5 24. Qf5 Qe7 25. Ng4 Nxg4 26. Qxg4
Rad8 27. Red1 g6 28. h4 Ne6 29. Rxd7 Qxd7 30. h5 Ng5 31. Qe2 Qd3 32. Qg4
Kg7 33. Rf1 Qd2 34. f4 Qe3+ 35. Kh2 exf4 36. Rxf4 Qc5 37. hxg6 fxg6 38. Ne2
Qe5 39. Kg1 Rd1+ 40. Kf2 h5 41. Qh4 Rd2 42. Kf1 Rxb2 43. Nd4 Kh6 44. Rg4
Nf7 45. Qh3 Qf6+ 46. Nf3 Ne5 47. Rg3 Nxf3 48. Rxf3 Qg5 49. Kg1 Re2 50. Rg3
Qe5 51. Rg4 Qe6 52. Rf4 Qxh3 53. gxh3 Kg5 54. Rf7 Rxe4 55. Rxb7 Rxa4 56.
Ra7 Kh4 57. Rg7 g5 0-1
[Event "57th Capablanca Mem"]
[Site "Havana CUB"]
[Date "2024.05.03"]
[Round "1"]
[White "Romanov,E"]
[Black "Ponomariov,R"]
[Result "0-1"]
[WhiteElo "2598"]
[BlackElo "2646"]
[EventDate "2024.05.03"]
[ECO "E10"]
1. d4 Nf6 2. c4 e6 3. Nf3 d5 4. g3 Bb4+ 5. Bd2 a5 6. Bg2 O-O 7. Qc1 Be7 8.
O-O c6 9. Nc3 Nbd7 10. Rd1 dxc4 11. Bg5 Nd5 12. Bxe7 Qxe7 13. e4 Nxc3 14.
bxc3 e5 15. Nxe5 Nxe5 16. dxe5 Qxe5 17. Qe3 f6 18. a4 Be6 19. Qb6 Qxc3 20.
Qxb7 Rac8 21. Qa7 Rfd8 22. Rdc1 Qe5 23. Rab1 Rb8 24. Rxb8 Rxb8 25. h4 Qb2
26. Bf1 h5 27. Rc2 Qb1 28. Rc1 Qxc1 29. Qxb8+ Kh7 30. Qe8 Bg4 31. Kg2 Qd1
0-1
I going over the pgn file line by line and try to match using this commnad, can you tell me why it doesn’t match my lines?