[librecat-dev] Catmandu marc questions
Johann Rolschewski
rolschewski at gmail.com
Sat Sep 10 13:58:10 CEST 2016
Hi Lars,
> The example provided by /Johann,/ instead of doing the below, how one could give as input a txt file named OldNames.csv and the replacements be in a file named NewNames.csv?
you can use lookup tables as Patrick described in one of his last posts:
1. Create CSV files
names.csv:
oldname,newname
name1a,name1b
name2a,name2b
name3a,name3b
titles.csv:
oldtitle,newtitle
title1a,title1b
title2a,title2b
title3a,title3b
2. Create a fix file
replace.fix:
do marc_each()
marc_map(100a,tmp.name);
lookup(tmp.name,names.csv,delete:1)
if exists(tmp.name)
marc_set(100a,$.tmp.name)
remove_field(tmp.name)
end
marc_map(245a,tmp.title);
lookup(tmp.title,titles.csv,delete:1)
if exists(tmp.title)
marc_set(245a,$.tmp.title)
remove_field(tmp.title)
end
remove_field(tmp)
end
3. Run conversion
$ catmandu convert MARC to MARC --fix replace.fix < input.mrc > output.mrc
> last, i do not know how to produce a clean report,
> say i wanted to have a txt file with all 001 values, or a tag that is repeatable....
>
> i noticed
>
> catmandu convert --fix 'retain(_id)' MARC to YAML < file_0.mrc
>
> has an output that adds for example ' character, when we have a digit
>
> ---
> _id: '120090304134844'
> ...
> ---
> _id: recorda
> ...
> ---
> _id: recordb
> ...
> ---
> _id: recordc
> ...
> ---
> _id: recorde
> ...
> ---
> _id: '8797989999140813'
>
> Is there a way to have just the values, in a row by row format?
I don't know any possibility to generate a CSV report while doing a MARC
to MARC conversion with Catmandu. You could use another fix and generate
CSV reports for the input and output and join them afterwards.
4. Create a fix file:
report.fix:
marc_map(100a,name)
marc_map(245a,title)
5. Run conversions:
$ catmandu convert MARC to CSV --fix report.fix --fields _id,name,title
< input.mrc > input.csv
$ catmandu convert MARC to CSV --fix report.fix --fields _id,name,title
< output.mrc > output.csv
6. Generate report:
$ join -t , input.csv output.csv > report.csv
Johann
More information about the librecat-dev
mailing list