#!/bin/bash #################################### # # Processing a comma separated file # using a command line argument for the file # Author: Bill Kraynek # ##################################### # Get the file from command line as parameter 1 file=$1 # Eliminate the quotes tr -d "\"" < $file > temp1 # Pick out week and season fields cut -d, -f1-3 temp1 > week cut -d, -f1,7-8 temp1 > season sort week > temp2 sort season > temp3 # Recombine season and week join -1 1 -2 1 -t, -o "1.1 1.2 2.2" temp3 temp2 > temp4 sort -t, -k 2 -g -r temp4 > temp5 awk -F, ' BEGIN { { print "\n\tResults\nName\t Season\t Week\n"} } {t1+=$2;t2+=$3;printf "%-10.10s %5s\t%5s\n",$1,$2,$3};END {printf "%-10.10s %5s\t%5s\n","Total",t1,t2}' temp5 > results; cat results # Setup for example of the uniq command cat week season | awk -F, '{printf ",%s,\n",$1}' | sort > temp6 uniq -c temp6 > temp7 awk -F, ' BEGIN { {print "\n\tExample\n"} } {printf "%-8.8s appeared%3d times\n",$2,$1}' temp7 > final_results; cat final_results rm temp1 temp2 temp3 temp4 temp5 temp6 temp7