Enhancements to the MarcEdit Replace Function — making complex conditional edits easy

By reeset / On / In MarcEdit

MarcEdit provides lots of different ways for users to edit their data.  However, one use case that comes up often is the ability to perform an action on a field or fields based on the presence of data within another field.  While you can currently do this in MarcEdit by using tools to isolate the specific records to edit, and then working on just those items — more could be done to make this process easier.  So, to that end, I’ve updated the Replace Function to include a new conditional element that will allow MarcEdit to presort using an in-string or regular expression query, prior to evaluating data for replacement.  Here’s how it will work…

When you first open the Replace Window:

Replace Function Changes

Notice that the conditional string text has been replaced.  This was confusing to folks – because maybe that didn’t reflect exactly what was being done.  Rather, this is an option that allows a user to run an instring or Regular Expression search across your entire record before the Find/Replace is run.  The search options grouped below – these *only* affect the Find/Replace textboxes.  They do not affect the options that are enabled when the Perform Find/Replace If…is checked.  Those data fields have their own toggles for instring (has) or regular expression (regex) matching.

 

If you check the box, the following information will be displayed:

New Replace Functionality

Again – the If  [Textbox] [REGEX] is a search that is performed and must evaluate as true in order for the paired find and replace runs.  The use case for this function are things like:

  • I want to modify the field x but only if foobar is found in field y.

 

There are other ways to do this by extracting data from files and creating lots of different files for processing or writing a script – but this will give users a great deal more flexibility when wanting to perform options, but only if specific data is found within a field.

 

A simple example would be below:

Example of the new Replace

This is a non-real world example of how this function works.  A user wants to change the 050 field to an 090 field, but only if the data in the 945$a is equal to an m-z.  That’s what the new option allows.  By checking the Perform Find/Replace If option, I’m allowed to provide a pre-search that will then filter the data sets that I’m going to actually perform the primary Find/Replace pair on.  Make sense?  I hope so.

Finally – I’ve updated the code around the task wizard so that this information can be utilized within tasks.  This enhancement will be in the next available update.

–tr

8 thoughts on “Enhancements to the MarcEdit Replace Function — making complex conditional edits easy

  1. Hi Terry,

    when I tried a simple Find/Replace (not conditional, just performing a change across all records), the records were all wiped. I wasn’t sure if this resulted from a fluke with the batch, so I tried a similar action on another batch and same thing. Has this update changed the way to perform a simple Find/Replace, and if I wanted to do just that should I be checking/not checking something off?
    Thanks!

    1. Hi Gemma,

      Yep, I introduced a bug into the replace function that would occur when data wasn’t processed using regular expressions. I’ve corrected it and posted the update. The program should notify you of the fix next time you open the program.

      –tr

  2. Hi Terry,

    I was just wondering whether I could use multiple conditions with this function.

    Say for example if I would like to replace 050 with 090 if 945$a is equal to an m-z and 856$a is equal to a?

    Thanks,

    1. Maybe. Practically, the answer is no because the tool provides the single conditional evaluation. Technically, yes — but you’d need to be able to craft the regular expression. The conditional evaluation evaluates the entire record, not an individual field. So, you could potentially craft an expression that tested for the two values together. Something kind of like: (.*)(=856.{4}\$aa)(.*)(=945.{4}\$a[m-z])(.*)

      This probably isn’t going to work as is — but something like this (but you will need to know something about your data to make this work).

      –tr

  3. Is there a way to do this so that I am editing/inserting a field based on the absence of another field? For example, could I insert a 090 based on the absence of a 050 in the record?

    1. Hi Amber,

      I think that the best way to do this is to use the Tool that allows you to extract a subset of data. It makes this a two step process — but one that is much cleaner. You would do this by loading your data into the MarcEditor, then File/Select Records for Edit. Import the data, using the field that you are interesting in looking for the presence of — as the display field. Then use the checkbox to select records missing that field. Export the data out — and the MarcEditor will now just have those records for edit. Make your changes, then save — and save will save back into your source file replacing the original records.

      –tr