#! /bin/bash
# getrecord
# Get specific record(s) from larger file of marc records.
# $Id: getrecord

E_BADARGS=65

scriptdir=$( (cd -P $(dirname $0) && pwd) )
if ! [ -e $scriptdir/SolrMarc.jar ] 
then
  scriptdir=$( (cd -P $(dirname $0)/.. && pwd) )
fi

if ! [ -p /dev/stdin ]
then  
  if [ $# -eq 0 ]
  then
    echo "    Usage: `basename $0` ./path/to/marcfile.mrc regex_of_ids_to_extract"
    echo "    Usage: `basename $0` ./path/to/marcfile.mrc -h field_that_must_be_present"
    echo "    Usage: `basename $0` ./path/to/marcfile.mrc file_with_list_of_ids.txt"
    
    exit $E_BADARGS
  fi
  arg1=$1
  arg2=$2
  arg3=$3
else
  arg1=-
  arg2=$1
  arg3=$2
  arg4=$3
fi

java -Dsolrmarc.main.class="org.solrmarc.marc.RawRecordReader" -jar $scriptdir/SolrMarc.jar $arg1 $arg2 $arg3 $arg4

exit 0

