Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created January 23, 2012 21:13
Show Gist options
  • Save mark-cooper/1665565 to your computer and use it in GitHub Desktop.
Save mark-cooper/1665565 to your computer and use it in GitHub Desktop.
Updating a field/subfield value with ruby-marc
require 'marc'
TAG = '856'
SUB = 'y'
STR = 'Img100'
REP = 'Img200'
count = 0
w = MARC::Writer.new('dla_fixed.mrc')
MARC::ForgivingReader.new('records/dla.mrc').each do |r|
if f = r.find { |f| f.tag == TAG and f[SUB] =~ /#{STR}/ }
f[SUB].gsub!(/#{STR}/, REP)
w.write r
count += 1
end
end
w.close
puts count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment