<div dir="ltr"><div><div><div>Thanks!<br><br></div>Note: the last command (conversion back to MARC) also has to have "--header 0"<br><br></div>I also needed to sort by multiple keys. Ended up writing a simple Python script for the sorting step.<br><br></div>Uldis<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 14 September 2017 at 09:58, Patrick Hochstenbach <span dir="ltr"><<a href="mailto:Patrick.Hochstenbach@ugent.be" target="_blank">Patrick.Hochstenbach@ugent.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
There are many ways to do this. Basically the algoritm is:<br>
<br>
 * Extract the field you want to sort from MARC using marc_map<br>
 * Store the data somewhere (in memory, in a Catmandu::Store, …)<br>
 * Sort and export back to MARC<br>
<br>
You can do this on the command line also with the TSV exporter and to_json,from_json command to transform MARC into a line-by-record serialisation and sort this one using the UNIX ‘sort’ command. E.g.<br>
<br>
 catmandu convert MARC to TSV --header 0 --fix 'marc_map(245a,__sort); to_json(record)’  < camel.mrc \<br>
            | sort \<br>
            | catmandu convert TSV --fields '__sort,_id,record' to MARC --fix 'from_json(record)’<br>
<br>
Cheers<br>
<br>
Patrick<br>
<div><div class="h5"><br>
<br>
> On 13 Sep 2017, at 16:25, Uldis Bojars <<a href="mailto:captsolo@gmail.com">captsolo@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> Can Catmandu help with sorting a set of MARC records (by certain MARC fields / subfields)?<br>
><br>
> Since records are normally processed sequentially and separately, it does not seem like a good fit. But perhaps you have some advice on how to do it.<br>
><br>
> A quick-and-dirty non-Catmandu solution 'd be a custom script to load records into memory, to index / sort them by the required fields and to output them in this order.<br>
><br>
> Thanks,<br>
> Uldis<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> librecat-dev mailing list<br>
> - send list mails to <a href="mailto:librecat-dev@lists.uni-bielefeld.de">librecat-dev@lists.uni-<wbr>bielefeld.de</a><br>
> - to unsubscribe or change options, visit <a href="https://lists.uni-bielefeld.de/mailman2/cgi/unibi/listinfo/librecat-dev" rel="noreferrer" target="_blank">https://lists.uni-bielefeld.<wbr>de/mailman2/cgi/unibi/<wbr>listinfo/librecat-dev</a><br>
> - project website: <a href="http://librecat.org/" rel="noreferrer" target="_blank">http://librecat.org/</a><br>
<br>
</blockquote></div><br></div>