user34316: Is there a way to split large PGN files into folders grouped by the players?
For example, in a tournament, each player has several games in one file.
I aim to group each game by players to the respective folders (one game, one file).
So it will produce two files for each match, one for player 1 and one for player 2 in two separate folders.

user34197: Either you may be able to do it in a DB manager (ChessBase...) or you'll need a bit of coding in Chess Query Language

Download and extract cqli (a modern rewrite of the original cql software) to the folder containing your pgn database
Create a p1.cql file, with the following content (this is an example for getting all Kasparov's games) :
cql(input database.pgn)

"Kasparov" in player


Open Powershell/Terminal (depending on your platform), cd to the database directory and run
Unix/Linux
./cqli --threads 8 p1.cql

macOS
# For Intel Macs
./cqli-x86_64 --threads 8 p1.cql
# For Apple Silicon Macs
./cqli-arm64 --threads 8 p1.cql

Windows
./cqli.exe --threads 8 p1.cql


And you'll find the resulting database in p1-out.pgn.
Note that it is a database, to extract it, we can use kentdjb pgn-extract
Unzip the windows executable in the database program as previously, or build it from source if you are on Linux/macOS
And then run :
./pgn-extract -\#1 p1-out.pgn

The backslash before the # is essential
This will split your pgn into files named 1.pgn, 2.pgn...

34316: <p>Is there a way to split large PGN files into folders grouped by the players?
For example, in a tournament, each player has several games in one file.
I aim to group each game by players to the respective folders (one game, one file).
So it will produce two files for each match, one for player 1 and one for player 2 in two separate folders.</p>
 34197: <p>Either you may be able to do it in a DB manager (ChessBase...) or you'll need a bit of coding in <a href="http://www.gadycosteff.com/cql/" rel="nofollow noreferrer">Chess Query Language</a></p>
<hr />
<p>Download and extract <a href="https://cql64.com/" rel="nofollow noreferrer"><code>cqli</code></a> (a modern rewrite of the original <code>cql</code> software) to the folder containing your pgn database</p>
<p>Create a <code>p1.cql</code> file, with the following content (this is an example for getting all Kasparov's games) :</p>
<pre><code>cql(input database.pgn)

&quot;Kasparov&quot; in player
</code></pre>
<hr />
<p>Open Powershell/Terminal (depending on your platform), <code>cd</code> to the database directory and run</p>
<p>Unix/Linux</p>
<pre><code>./cqli --threads 8 p1.cql
</code></pre>
<p>macOS</p>
<pre><code># For Intel Macs
./cqli-x86_64 --threads 8 p1.cql
# For Apple Silicon Macs
./cqli-arm64 --threads 8 p1.cql
</code></pre>
<p>Windows</p>
<pre><code>./cqli.exe --threads 8 p1.cql
</code></pre>
<hr />
<p>And you'll find the resulting database in <code>p1-out.pgn</code>.</p>
<p>Note that it is a database, to extract it, we can use <a href="https://chess.stackexchange.com/users/12951/kentdjb">kentdjb</a> <a href="https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/" rel="nofollow noreferrer"><code>pgn-extract</code></a></p>
<p>Unzip the windows executable in the database program as previously, or build it from source if you are on Linux/macOS</p>
<p>And then run :</p>
<pre><code>./pgn-extract -\#1 p1-out.pgn
</code></pre>
<p><em>The backslash before the <code>#</code> is essential</em></p>
<p>This will split your pgn into files named <code>1.pgn</code>, <code>2.pgn</code>...</p>
