You're viewing a comment by jsalai49 and its responses.

jsalai49 Permalink
August 11, 2015, 13:10

Excellent blog! Thanks!

A humbly try :)
Probably interesting use of skip-branch (!b), branching ALL EXCEPT; didn't see it around.
Working perfectly with GNU sed v 4.2.1 for Windows
Please, comment!

sed -e "/^{/ !b" wrk4.pgn -e "/Diagram/ b" -e "/%tqu/ b" -e d

or

sed -e "/^{/ !b" wrk4.pgn -e "/Diagram\|%tqu/ b" -e d

From the input lines all lines should be preserved, except those beggining with a "{" AND NOT containing strings "Diagram" OR "%tqu".

Input:
[White "Sokolov"]
[Black "Tseshkovsky"]
[Result "0-1"]
1. c4 e5 2. g3 d6 3. Bg2 g6 4. e3 Bg7 5. Ne2 h5 6. d4 h4
{ keep - Diagram }
7. Nbc3 Nh6 8. e4 Bg4 9. Qd3 Nd7 10. d5 Nc5 11. Qe3 h3
{ foo bar baz - Should be deleted }
12. Bf1 f5 13. f3
{ [%tqu "bar","","",Nb4+,"baz",2] - keep }
13... fxe4 14. fxg4 Nxg4 15. Qg1 Qf6
{ Diagram - keep }
16. Nd1 Nd3+ 17. Kd2 Qf3 18. a3 Bh6+ 19. Kc2
{ keep - [%tqu "bar","","",Nb4+,"baz",2] }
19... Nb4+ 0-1

Output:
[White "Sokolov"]
[Black "Tseshkovsky"]
[Result "0-1"]
1. c4 e5 2. g3 d6 3. Bg2 g6 4. e3 Bg7 5. Ne2 h5 6. d4 h4
{ keep - Diagram }
7. Nbc3 Nh6 8. e4 Bg4 9. Qd3 Nd7 10. d5 Nc5 11. Qe3 h3
12. Bf1 f5 13. f3
{ [%tqu "bar","","",Nb4+,"baz",2] - keep }
13... fxe4 14. fxg4 Nxg4 15. Qg1 Qf6
{ Diagram - keep }
16. Nd1 Nd3+ 17. Kd2 Qf3 18. a3 Bh6+ 19. Kc2
{ keep - [%tqu "bar","","",Nb4+,"baz",2] }
19... Nb4+ 0-1

Comment Responses

Anirudh Permalink
February 01, 2016, 15:06

The default action is to print the pattern space, so the below can be also written as:

>> sed -e "/^{/ !b" wrk4.pgn -e "/Diagram\|%tqu/ b" -e d <<
   sed -e "/^{/ !b" wrk4.pgn -e "/Diagram\|%tqu/!d"

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "coding_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.