#! /bin/sh tr '\325' "'" < holin.txt | awk '{what=$1;for(i=2;i<=NF;i++)what=what " " $i} (1==(NR%4)){name=what} (2==(NR%4)){type=what} (3==(NR%4)){cdat=what} (0==(NR%4)){ odat = what if ("University Holiday"==type) name = name " (19)" if (cdat==odat) { printf "%s\t%s\t%s\n",name,cdat,cdat } else { split(cdat,cx," ") if (2==split(cx[2],x,",")) cx[2] = x[1] cd = substr(cx[1],1,3) " " substr(cx[2],1,2) split(odat,ox," ") if (2==split(ox[2],x,",")) ox[2] = x[1] od = substr(ox[1],1,3) " " substr(ox[2],1,2) if (ox[3]!=cx[3]) { cd = cd " '"'"'" substr(cx[3],3,2) od = od " '"'"'" substr(ox[3],3,2) } printf "%s (Obs %s)\t%s\t%s\n",name,od,cdat,cdat printf "%s (Cal %s)\t%s\t%s\n",name,cd,odat,odat } }' >holout.txt tr '\012' '\015' macholout.txt