#!/usr/bin/gawk -f
#extract a coin by serno (use getbyser.awk find=abcd1234 to find
#all certs with a serno of abcd1234)

{
  if( $0 ~ /^-----BEGIN SIGNED COIN-----/ ||
      $0 ~ /^-----BEGIN SIGNED BLINDED COIN-----/ ||
      $0 ~ /^-----BEGIN UNBLINDER/ ||
      $0 ~ /^-----BEGIN SIGNED TITLE-----/ ||
      $0 ~ /^-----BEGIN BLINDED COIN-----/ ){
    count = 0;
    test = $0;
    save = $0;
    sub("-----BEGIN ","-----END ", test);
    getline;

    if( $3 == toupper(find) ) {
      print save;
      print;
      while( count++ < 12 && !( $0 ~ "^" test ) ){
        getline;
        print;
      }
      if( count == 13 )
        print test "\nABOVE IS AN ERROR!!!";
    }
  }
}
