On Fri, Aug 08, 2014 at 08:46:24PM -0400, Tom Connolly wrote:
> >> Is there an open source way to format the dewey code for printing book
> >> labels? Or can someone tell me how to isolate just the dewey number from a
> >> marc file (I have MarcEdit; is there a better tool for this simple task?)
> >> so it is the only field sent to the printer? (I'm using Ubuntu 14.04 and
> >> printing to a Dymo 450) Thanks
> >> Tom Connolly
Something like this might work.
./print_marc.lisp foo.mrc | egrep -m 1 '^082|^083' | lpr -h
print_marc.lisp is:
#!/usr/bin/env clisp
;;; Program to print a file in MARC communications format
;;; human-readably.
(defvar *file* (car *args*))
(defun print-directory-entries (input base-address-of-data limit ptr step)
(cond ((= limit 0))
(t (let* ((directory-entry (subseq input ptr (+ ptr step)))
(tag (subseq directory-entry 0 3))
(field-length (parse-integer (subseq directory-entry 3 7)))
(starting-character-position (parse-integer (subseq directory-entry 7 12)))
(field-start (+ base-address-of-data starting-character-position))
(field-end (+ field-start field-length))
(data (subseq input field-start field-end)))
(format t "~a ~a~%" tag data)
(print-directory-entries input base-address-of-data (decf limit) (+ ptr step) step)))))
(defun process (input)
"A MARC record contains a leader, followed by a directories listing,
followed by data. The leaders is 24 characters long. The first five
characters are the record length. Characters 12-16 indicate where the
data section begins. The first three characters of a directory entry
indicate the MARC tag. Characters 3-6 are the field length. Characters
7-11 are the starting character position of the corresponding data
relative to the base address of the data. Numbering begins from 0."
(let* ((leader (subseq input 0 24))
(leader-length 24)
(directory-record-length 12)
(record_length (parse-integer (subseq input 0 5)))
(base-address-of-data (parse-integer (subseq input 12 17)))
(length-of-field (parse-integer (subseq input 20 21)))
(length-of-directory (- base-address-of-data (+ 1 leader-length)))
(number-of-fields (/ length-of-directory directory-record-length)))
(format t "~a~%" leader)
(print-directory-entries input base-address-of-data number-of-fields leader-length directory-record-length)))
(with-open-file (stream *file*)
(do ((input (read-line stream nil)
(read-line stream nil)))
((null input))
(process input)))
I'm not sure how you'd do it with MarcEdit.
--
Charles Blair, Director, Digital Library Development Center, University of Chicago Library
1 773 702 8459 | [log in to unmask] | http://www.lib.uchicago.edu/~chas/
|