#!/bin/bash TABLE_FORMAT="%-35s%8s\n" NUM=$(cat $1 | grep lammi87 | wc -l) printf $TABLE_FORMAT "All my contributions in total:" $NUM > $3 # I get: 730 # But from this section, I get: 912 echo -e "\n\nMy contributions per hardware class:" >> $3 printf "%s\n\n" $THICK_LINE >> $3 for CLASS in notebook videocard soundcard wifi ethernet-card \ sd-card-reader webcam bluetooth acquisition-card 3G-card \ host-controller fingerprint-reader RAID-adapter modem printer \ scanner do DEVICE_NAMES=$( sed -rn 's/^'"$CLASS"'\s+(.+)\s+/\1/p' "$2" ) if [ -n "$DEVICE_NAMES" ]; then let "NUM=$(fgrep -c "$DEVICE_NAMES" $1)" else NUM=0 fi printf $TABLE_FORMAT $CLASS $NUM >> $3 let "TOTAL=$TOTAL+$NUM" done printf "%s\n" $THIN_LINE >> $3 printf $TABLE_FORMAT "Total" $TOTAL >> $3 cat $3