Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Looking for a written lesson on an awk script to parse data. I have a quiz on th

ID: 3684682 • Letter: L

Question

Looking for a written lesson on an awk script to parse data. I have a quiz on this and will be working on sample problems, I do not have a correct version to compare mine to so I am looking for someone to show me what the correct script looks like. Here's the sample problem: Write an awk script that will parse the data, and for each county, print the county name, the population per square mile of land, and the percentage of the county that is water. (Note that the total area of the county is the sum of the land and water areas.) At the end, your script should print the county name and the value for the following criteria. Highest population density Lowest population density Highest percentage of water Lowest percentage of water Example output (not with correct data): County Population/sq mile % Water Adams County 307.2 88.1% Asotin County 111.8 12.6% [... etc ...] Highest population density: Adams County, 9999 people/square mile Lowest population density: Pierce County, 3 people/square mile Highest percentage of water: Whitman County, 90.2% water Lowest percentage of water: Skagit County, 3.6% water

Explanation / Answer

#!/bin/bash
filedata=/home/population.txt
$lowestland = 99999
$lowestwater = 99999
$highestland = 0
$highestwater = 0
dataFetch() {
while IFS=: read countryName population water; do
print "countryName:", $countryName
print "percenatage of population of land:", $population
print "percentage of the county that is water:", $water

if($population < $lowestland)
$lowestland = $population

if($water < $lowestwater)
$lowestwater = $water

if($population > $highestland)
$highestland = $population

if($water > $highestwater)
$highestwater = $water
done < "$filedata"
print "high density population",$highestland
print "Low density population",$lowestland

print "high water county",$highestwater
print "Low water county",$lowestwater
}
dataFetch

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote