Tool

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Ponti
Posts: 493
Joined: Wed Mar 15, 2006 6:13 am
Location: Curitiba - PR - BRAZIL

Tool

Post by Ponti »

I need a tool to delete all moves from a database, remaining only the initial positions of each "problem".

Database is in chessbase format, but obviously I can convert it to pgn first.
A. Ponti
AMD Ryzen 1800x, Windows 10.
FIDE current ratings: standard 1913, rapid 1931
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Tool

Post by Ferdy »

Ponti wrote:I need a tool to delete all moves from a database, remaining only the initial positions of each "problem".

Database is in chessbase format, but obviously I can convert it to pgn first.
Can you show in the pgn format an example, both the original and the final output format?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Tool

Post by hgm »

Seems to me such a tool is called a text editor. Just delete all lines from the PGN except the FEN tag, and then the [FEN " prefix and the "] suffix, and you have a file of FENs. Five commands in ed.
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Tool

Post by stegemma »

hgm wrote:Seems to me such a tool is called a text editor. Just delete all lines from the PGN except the FEN tag, and then the [FEN " prefix and the "] suffix, and you have a file of FENs. Five commands in ed.
Or less, in Windows command prompt:

Code: Select all

sort db.pgn>fen.txt
then edit the file and keep only the lines with [FEN...], that are all grouped together!
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Tool

Post by Sven »

stegemma wrote:
hgm wrote:Seems to me such a tool is called a text editor. Just delete all lines from the PGN except the FEN tag, and then the [FEN " prefix and the "] suffix, and you have a file of FENs. Five commands in ed.
Or less, in Windows command prompt:

Code: Select all

sort db.pgn>fen.txt
then edit the file and keep only the lines with [FEN...], that are all grouped together!
@Aloisio:

At Windows command prompt:

Code: Select all

findstr "FEN " db.pgn | sort > fen.txt
and then edit "fen.txt" with a text editor, indeed ...

In UNIX-like shell (e.g. Cygwin bash):

Code: Select all

grep 'FEN ' db.pgn | sed 's/^.FEN "\(.*\)"$/\1/' | sort -u > fen.txt
User avatar
Ponti
Posts: 493
Joined: Wed Mar 15, 2006 6:13 am
Location: Curitiba - PR - BRAZIL

Re: Tool

Post by Ponti »

Ok, but... what if I have a file with 5.000 positions with the answers, I want to delete the answers and get only the diagrams.

To edit that manually... oh... 5.000 games ?

Is there another way to do it ?
A. Ponti
AMD Ryzen 1800x, Windows 10.
FIDE current ratings: standard 1913, rapid 1931
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Tool

Post by hgm »

That is not more work (for you) than editing a single game, right? Most editors have a 'Replace all' command. Even MS NotePad. All is all. Even when it are a million games. Just takes the computer a bit longer.
User avatar
Ponti
Posts: 493
Joined: Wed Mar 15, 2006 6:13 am
Location: Curitiba - PR - BRAZIL

Re: Tool

Post by Ponti »

Thanks and sorry to bother you.
I´m not a programmer.
With your help I managed to do it !

After extracting only the [FEN ...] and using notepad, I converted the epd file back again to another .pgn file. Now I have only the positios, without the answers.

It was a .cbh file, converted to .pgn, of all positions in a book (by Andrei Volokitin), commented in russian (well, I can´t read russian).
A. Ponti
AMD Ryzen 1800x, Windows 10.
FIDE current ratings: standard 1913, rapid 1931
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Tool

Post by hgm »

No bother, you are more than welcome. That is what forums are for!