/home/wpollock1/public_html/restricted/ShellScripting/Proj-5 awk countries model soln.txt

#!/bin/bash -
# Scripting project:  An AWK program to print the population per square mile
# for each country in Europe,
# and when done print the total population of Europe.
#
# The source data comes from $HOME/countrys.dat, whose format is:
#    Country_Name    Area     Pop    Continent
# The Area is in thousands of square miles, and the population is in
# millions of people.
#
# Written by Wayne Pollock, Tampa FL, 1997

cat $HOME/countrys.dat |awk '
    BEGIN           { FS = "\t"        # Set the field separator to a tab.
                      print ""
                      print "  Country ", "         People per"
                      print " in Europe", "        Square Mile"
                      print " ---------", "       -------------"
                    }

    $4 == "Europe"  { totalpop = totalpop + $3;
                      printf("  %-15s   %8.2f\n", $1, $3 * 1000 / $2 )
                    }

    END             { print ""
                      print "Total population of Europe:", totalpop, "million"
                    }
' # End of awk program