Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with these three questions and make comments if possible so I can understand. 3. Awk . Your code for this and the next

Please help with these three questions and make comments if possible so I can understand.

3. Awk. Your code for this and the next two question will be graded by a script so be sure that your scripts have the right names and produce the correct output (when run on mlc104).

The csumb.osm file contains data about roads around CSUMB. The file is in XML format, and contains information about "ways" (like stretches of road) and "nodes" points along a road. Write an awk script named make-nodes-table.awk that will extract node information from a .osm file. Your script should do this on the csumb.osm file: $ awk -f make-nodes-table.awk csumb.osm | wc 289 289 9734 $ awk -f make-nodes-table.awk csumb.osm | head -15 node_id,lat,long 1647008557,36.6536840,-121.7938995 421381587,36.6440097,-121.8066305 1646442592,36.6444397,-121.8064060 89819313,36.6461624,-121.8055179 1646442620,36.6446496,-121.8062964 89819334,36.6480528,-121.8067458 2935611310,36.6478826,-121.8060726 2935611314,36.6479609,-121.8058399 2935611315,36.6480277,-121.8063213 89801177,36.6409070,-121.8020990 89821442,36.6439543,-121.8028688 89821444,36.6437400,-121.8028720 89821446,36.6432520,-121.8030660 89821448,36.6428490,-121.8030920 $ awk -f make-nodes-table.awk csumb.osm | tail -15 2342889689,36.6551549,-121.7670867 3727683587,36.6551113,-121.7716948 3727683588,36.6551441,-121.7709472 3727683589,36.6551905,-121.7663836 89880441,36.6595260,-121.7787770 2342889693,36.6552093,-121.7649071 89954271,36.6554350,-121.7584980 89933309,36.6650290,-121.8008020 89933312,36.6649700,-121.8003770 89933314,36.6649210,-121.8001720 89933318,36.6648190,-121.7999010 89933321,36.6646840,-121.7996710 89933323,36.6645870,-121.7995480 89933326,36.6644810,-121.7994380 89933331,36.6642690,-121.7992770 I have provided the complete correct output file csumb-nodes.csv for you to test your code against.

4. Write an awk script named make-road-table.awk that will extract road data from an .osm file. Your script should work as follows on the csumb.osm file: $ awk -f make-road-table.awk csumb.osm | wc 279 662 10251 $ awk -f make-road-table.awk csumb.osm | head -15 road,way_id,seq_num,node_id Engineer Road,10459706,1,89705976 Engineer Road,10459706,2,89798118 Engineer Road,10459706,3,89798120 Engineer Road,10459706,4,89798122 Engineer Road,10459706,5,89798124 Engineer Road,10459706,6,89798126 Engineer Road,10459706,7,89798128 Engineer Road,10459706,8,89798130 5th Cutoff Street,10461171,1,89804458 5th Cutoff Street,10461171,2,89804460 5th Cutoff Street,10461171,3,89804463 5th Cutoff Street,10461171,4,89804464 5th Cutoff Street,10461171,5,89804466 5th Cutoff Street,10461171,6,89804468 $ awk -f make-road-table.awk csumb.osm | tail -15 Inter-Garrison Road,205167594,7,2342889683 Inter-Garrison Road,205167594,8,89994529 Inter-Garrison Road,205167594,9,89994530 Inter-Garrison Road,205167594,10,3727683588 Inter-Garrison Road,205167594,11,3727683587 Inter-Garrison Road,205167594,12,3727683584 Inter-Garrison Road,205167594,13,89994533 Inter-Garrison Road,205167594,14,89899515 Inter-Garrison Road,205167594,15,89917014 Inter-Garrison Road,205167594,16,373831767 Inter-Garrison Road,205167594,17,89808878 Light Fighter Drive,441628696,1,2935611310 Light Fighter Drive,441628696,2,2935611307 Light Fighter Drive,441628696,3,2935611305 Light Fighter Drive,441628696,4,89819293 I have provided the complete correct output file csumb-roads.csv for you to test your code against. Hint: the awk string function 'split' can be handy in picking parts out of a line of the .osm file.

5. The file queries.sql contains some SQL questions (on lines beginning with "--") and answers to those problems. Write an awk script get_query.awk that will get the answer for a specified problem. Your script should do this: $ awk -f get_query.awk -v PROB=2 queries.sql select occupation, round(avg(amount)) from contributor natural join contribution where occupation in ("STUDENT", "TEACHER", "LAWYER") group by occupation; $ awk -f get_query.awk -v PROB=11 queries.sql select substr(name, 1, instr(name, ",")-1) as last, zip, count(*) as cnt from contributor group by last, zip having cnt > 6 order by cnt desc; $ awk -f get_query.awk -v PROB=12 queries.sql select contbr_name, sum(amount), count(*) as cnt from c_summary group by contbr_name having cnt > 75 order by cnt desc;

csumb.osm, csumb-nodes.csv, queries.sql file found here: (scroll all the way through to see other files)

https://docs.google.com/document/d/1ID_GILE61o1EfkY_vqFop2ByqL1r0PYnt4kW_LLz1gQ/edit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

Describe three other types of visual aids.

Answered: 1 week ago