bartikowskiw / marcli

MarCLI - Command Line Utility handling MARC files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MARC CLI Tools

Command line tool collection for MARC record files.

Installation

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

Use the phar archive

The phar archive is part of the release branch of this repository. You can download the file there.

Manual installation

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

Make Marcli globally executable

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.

Basic MARC functions

# 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

Find / Find & replace

marcli marc:find beef random.mrc
marcli marc:replace beef pork random.mrc

Narrowing the search

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

Leader

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

Regular expressions

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

Boolean operations

# 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

Using stdio & pipes

# 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

Lookup table

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.

About

MarCLI - Command Line Utility handling MARC files


Languages

Language:PHP 82.6%Language:Shell 17.3%Language:Batchfile 0.1%