Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: PGN to FEN

Author: Russell Reagan

Date: 19:46:17 03/06/04

Go up one level in this thread


On March 06, 2004 at 22:28:08, Jeff White wrote:

>I have a file of positions in pgn format, 1154 of them to be exact. Here is an
>example of one:
>
>[Event "Combination Challenge!"]
>[Site "?"]
>[Date "1992.??.??"]
>[Round "?"]
>[White "01"]
>[Black "?"]
>[Result "*"]
>[SetUp "1"]
>[FEN "3rn1k1/p4ppp/1p4b1/2p1Q3/2P1P3/P4P2/1B1qBP1P/1R5K w - - 0 1"]
>[PlyCount "0"]
>[EventDate "1991.??.??"]
>[SourceDate "2002.08.06"]
>
>What I want to do is just have the fen line without everything else. I tried the
>program pgn2fen without success. I don't want to have to edit out everything
>except the fen line with a word processor. Basically I want 1154 fen lines. How
>do I go about doing this? Any help anyone can provide is greatly appreciated.
>Thanks very much.
>
>Regards,
>Jeff

Use grep to get only the FEN lines. Use sed in addition to grep if you want to
strip off just the actual FEN string.

This command will dump all of the FEN lines into newfile.txt:

grep '^\[FEN' file.pgn > newfile.txt

This command would get you just the FEN strings, and dump them into a new file:

cat file.pgn | grep '^\[FEN' | sed 's/^\[FEN \"\(.*\)\"\].*/\1/' > file.fen

If you don't have these fine programs, you can get them from one of the 'GNU for
Windows' projects like Cygwin or MinGW, or you can send me the PGN file and I'll
do it for you.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.