nodes_per_tree.sh 626 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/bin/bash
# file: nodes_per_tree.sh
#
# usage: ./prepare_data.sh <inputfile>
#
# Program: Counts the number of nodes per line. Ouputs the maximal, 
#          minimal and average number of nodes per line of the given 
#          inputfile containing a tree in bracket notation per line.
#
# Author: Thomas Huetter

if [ -z "$1" ]
  then
    echo "Argument missing."
    echo "Usage: ./prepare_data.sh <inputfile>"
    exit 1
fi

awk -F '\{' '{print NF-1}' $1 | awk 'NR == 1 { max=$1; min=$1; sum=0 }
   { if ($1>max) max=$1; if ($1<min) min=$1; sum+=$1;}
   END {printf "Min: %d\tMax: %d\tAverage: %f\n", min, max, sum/NR}'