#!/bin/bash

#how to run the script
#create a list and store it to file, in this example 1
#cat 1 | xargs -n1 | xargs -i= ~/bin/grep_error.unx "Register mismatch" =

cmd="grep "\"${1}\"" "${2}

#$cmd
#because xargs does not accept parameter with spaces
echo $cmd > tmp
chmod u+x tmp
./tmp > /dev/null

if [ $? -eq 0 ] ; then
  cmd="grep \"sn load \" "${2}" | sed 's/sn load //' | sed 's/ncsim> *//'"
  echo $cmd > tmp

  cnt="0"
  wc -l grep_error.txt >& /dev/null
  if [ $? -eq 0 ] ; then
    cnt=`wc -l grep_error.txt`
    echo "echo $cnt | sed \"s/ grep_error.txt//\"" >> tmp
  else 
    echo "echo 0" >> tmp
  fi

  echo "echo "$2 >> tmp
  echo "echo "$1 >> tmp
  chmod u+x tmp
  ./tmp >> grep_error.txt
fi