#!/usr/bin/env bash #----------------------------------------------------------------------- # call: tiki_get_parameter parameter_file parameter job_number # comment lines ("# ...") are not parsed automatically: for them $1 = "#" # # if job_number != "%" assume following format of each line: # # name min_run max_run value # # if job_number = "%" assume that the run numbers are not present and # each line has format as follows: # # name value #----------------------------------------------------------------------- input_file=$1 local_PARAMETER=$PARAMETER local_JOB_NUMBER=$JOB_NUMBER export PARAMETER=$2 export JOB_NUMBER=$3 # echo input_file=$input_file # echo PARAMETER=$PARAMETER # echo JOB_NUMBER=$JOB_NUMBER if [ .$3 == "." ] ; then export JOB_NUMBER="." ; fi cat $input_file | \ awk '{ job=ENVIRON["JOB_NUMBER"]; \ if (job == "%") { \ if ($1 == ENVIRON["PARAMETER"]) { \ print $2 \ } \ } \ else \ if (($1 == ENVIRON["PARAMETER"]) && \ ((job == ".") || ((job >= $2) && (job <= $3)))) { \ print $4; \ } \ }' | sed 's/ //g' #-------------------------------------------------------------------------- # done, restore... #-------------------------------------------------------------------------- export PARAMETER=$local_PARAMETER export JOB_NUMBER=$local_JOB_NUMBER #--------------------------------------------------------------------------