CIT052 Index > awk Exercise 4

awk Exercise 4

Save the following data in a file named coordinates.txt.


A,0,0;B,3,4
C,4,7;D,2,9
E,8,2;F,0,6

Each line of the file contains the name of a point and its x-y coordinates, a semicolon, then the name of a second point and its x-y coordinates. Write an awk script that will do the following:

After you have processed all the records, generate two random numbers in the range 0 to 10 (inclusive). These will be coordinates for point "Q". Then generate two random numbers in the range 0 to 10 (inclusive) as point "R". Print the coordinates for these new points, then calculate and print the distance and city block distance for these new, random points.

Print the output to look like the following. Print only three numbers after the decimal point.

From A (0, 0) to B (3, 4): actual distance 5.000; city block distance 7
From C (4, 7) to D (2, 9): actual distance 2.828; city block distance 4
From E (8, 2) to F (0, 6): actual distance 8.944; city block distance 12
From Q (9, 2) to R (3, 7): actual distance 7.810; city block distance 11

When You Finish

Name your file for part 1 in the form lastname_firstname_coordinates.awk and email it to the instructor.