Looking for a tool

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

Looking for a tool

Postby Volker Pittlik » 19 Aug 2009, 16:20

I have a collection of pgn files sorted and named according to the extended Scid openings classification. In total almost 6000 files.

What I want to do now is to extract a certain number of games from each file into a new file so that I get a collection of a certain number of games of each opening. So far I did not find a tool what can do that automatically. I can do that manually but I'd like to finish before Christmas 2011. If there is nothing around (what at best even runs in linux) I can write something myself but why reinvent the wheel?

Any hints?

tia

vp
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland

Re: Looking for a tool

Postby Michel » 19 Aug 2009, 23:33

I don't know about a generic tool but if it is a one off-job you may consider writing a small Python script. Since the parsing of the pgn files does not involve chess knowledge (the information is contained in the name) this should be quite trivial.
Michel
 
Posts: 513
Joined: 01 Oct 2008, 12:15

Re: Looking for a tool

Postby Zach Wegner » 20 Aug 2009, 07:10

This is very simple for a shell+awk script. This takes the first 10 games of every PGN file in the current directory (*.pgn) and puts them in newfile.pgn.

Code: Select all
for file in *.pgn
do
   awk 'BEGIN { games = 0; state = 0; }
      /^[[]/ { state = 1; }
      /^[^[]/ { state = 2; }
      /^$/ { if (state == 2) { state = 0; games++; } if (games>=10) exit; }
      //' < $file
done > newfile.pgn
User avatar
Zach Wegner
 
Posts: 182
Joined: 26 Sep 2004, 22:02
Location: Austin, Texas, USA

Re: Looking for a tool

Postby Volker Pittlik » 20 Aug 2009, 09:31

Zach Wegner wrote:This is very simple for a shell+awk script....


Thank you very much! Meanwhile I found out it could be done with awk. But finding it out and writing it down are two different things :-).

Volker
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland


Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 17 guests