Command line tool collection for MARC record files.
Marcli has its own Package in the UMLTS Private Package Archives (PPA). Installing Marcli under Ubuntu is fairly simple:
sudo add-apt-repository ppa:umlts/marcli
sudo apt-get update
sudo apt-get install marcli
The phar archive is part of the release branch of this repository. You can download the file there.
Download Marcli via git:
git clone https://github.com/bartikowskiw/marcli.git
Change into the Marcli directory and get the dependencies:
cd marcli
composer --no-dev install
Making Marcli globally executable makes living easier. The simplest way
is to create a shell script in ~/bin
.
#!/bin/bash
php /path/to/marcli.php "$@"
Moving the phar archive to ~/bin is also a simple option.
# Echo a colored dump of the records
marcli marc:dump random.mrc
# Echo the number of record inside the file
marcli marc:count random.mrc
marcli marc:find beef random.mrc
marcli marc:replace beef pork random.mrc
The search can be narrowed by tag, subfield, and indicators
# Returns records with the needle "beef" in the MARC field 245 (which
# usually stores titles)
marcli marc:find --tag=245 beef random.mrc
The leader has its own special tag "LDR" or "LEADER":
# Returns records with set "d" (delete) flag in the leader
marcli marc:find --tag=LDR "^.....d" random.mrc
The search accepts PCRE regular expressions. This would look for record that contain the word "beef" or "pork" in any field:
marcli marc:find "(beef|pork)" random.mrc
# Returns records that exist in both MARC files (according to the id
# in the MARC 001 field).
marcli bool:add random.mrc random2.mrc
# Returns records that do exist in the first file but not in the second.
marcli bool:not random.mrc random2.mrc
# Same as marcli marc:count random.mrc
cat random.mrc | marcli marc:count
# Chainable with the --raw option:
cat random.mrc | marcli marc:find --raw needle | marcli marc:count
# Save the result to a new MARC file:
cat random.mrc | marcli marc:find --raw needle > needle.mrc
MARC files can get quite large. This function creates a SQLite database where the id in the 001 field and the position of the corresponding record in the file are saved. This makes searching for a records with a given id fast.
marcli map:write random.mrc
marcli map:read 123456 random.mrc
The map:read
command supports regular expressions. The --regexp
option turns this feature on:
marcli map:read --regexp "12345[0-3]" random.mrc
This command searches for the ids 123450, 123451, 123452, and 123453. Regular expressions should only be switched on if really needed. They significantly slow the lookups down.