Question: Please help AWK: get-problem Purpose. Knowing how to write simple awk scripts is a very valuable skill when working in bash. This assignment will help
Please help



AWK: get-problem Purpose. Knowing how to write simple awk scripts is a very valuable skill when working in bash. This assignment will help build your awk skills. Instructions. We'll write a script to find and output a problem in a homework file. Look at the file student-code.sql to see what a homework file looks like. Each problem is described on a problem line that starts with something like "--4.". The student response is on the lines following the problem. Given an input value, like 4, the script should output the student response to the problem. Please note that a student response ends with either: a new problem line, the end of the file, or a line that begins with three or more hyphens. Student responses can be more than 1 line long, and blank lines within a student response should not be output Note that the problem id is passed to the awk script as variable ID on the command line, like this: -V ID=6 You need to edit awk script get-problem.awk. Also, you will need to the "shebang line" #!/usr/bin/awk -f to the top of the script. The directory contains tests that your code should pass. I may use additional test scripts when I test your code. You don't need advanced features of AWK for these scripts. Do not use 'getline' or 'next', and stick to basic AWK programming. GNU nano 2.0.9 File: student-code.sql -- Edit this file by adding your SQL below each question. The following queries are based on the 1994 census data. .read 1994-census-summary-1.sql -- 4. what is the average age of people from China? select avg(age) from census where native_country ='China'; -- 5. what is the average age of people from Taiwan? select avg (age) from census where native_country ='Taiwan'; -- 6. which native countries have "land" in their name? select distinct (native_country) from census where native_country like 'flandt'; The following queries are based on the courses-ddl.sql and courses-small.sql data drop table census; .read courses-ddl.sql .read courses-small-1.sql -- 11. what are the names of all students who have taken some course? Don't show duplicates. select distinct (name) from student where tot_cred > 0; -- 12. what are the names of departments that offer 4-credit courses? Don't list duplicates. select distinct (dept_name) from course where credits=4; -- 13. What are the names and IDs of all students who have received an A in a computer science class? select distinct (name), id from student natural join takes natural join course where dept_name="Comp. Sci." and grade="A"; GNU nano 2.0.9 File: get-response. awk !/usr/bin/awk -f # get problem with problem id ID from problem file # usage: get-problem. awk -V ID=i problem-file.txt /*#@ / { if ($2 == ID) { state = "printing" } else { state = } } !/^#@/ { il (state "printing") print $0 } AWK: get-problem Purpose. Knowing how to write simple awk scripts is a very valuable skill when working in bash. This assignment will help build your awk skills. Instructions. We'll write a script to find and output a problem in a homework file. Look at the file student-code.sql to see what a homework file looks like. Each problem is described on a problem line that starts with something like "--4.". The student response is on the lines following the problem. Given an input value, like 4, the script should output the student response to the problem. Please note that a student response ends with either: a new problem line, the end of the file, or a line that begins with three or more hyphens. Student responses can be more than 1 line long, and blank lines within a student response should not be output Note that the problem id is passed to the awk script as variable ID on the command line, like this: -V ID=6 You need to edit awk script get-problem.awk. Also, you will need to the "shebang line" #!/usr/bin/awk -f to the top of the script. The directory contains tests that your code should pass. I may use additional test scripts when I test your code. You don't need advanced features of AWK for these scripts. Do not use 'getline' or 'next', and stick to basic AWK programming. GNU nano 2.0.9 File: student-code.sql -- Edit this file by adding your SQL below each question. The following queries are based on the 1994 census data. .read 1994-census-summary-1.sql -- 4. what is the average age of people from China? select avg(age) from census where native_country ='China'; -- 5. what is the average age of people from Taiwan? select avg (age) from census where native_country ='Taiwan'; -- 6. which native countries have "land" in their name? select distinct (native_country) from census where native_country like 'flandt'; The following queries are based on the courses-ddl.sql and courses-small.sql data drop table census; .read courses-ddl.sql .read courses-small-1.sql -- 11. what are the names of all students who have taken some course? Don't show duplicates. select distinct (name) from student where tot_cred > 0; -- 12. what are the names of departments that offer 4-credit courses? Don't list duplicates. select distinct (dept_name) from course where credits=4; -- 13. What are the names and IDs of all students who have received an A in a computer science class? select distinct (name), id from student natural join takes natural join course where dept_name="Comp. Sci." and grade="A"; GNU nano 2.0.9 File: get-response. awk !/usr/bin/awk -f # get problem with problem id ID from problem file # usage: get-problem. awk -V ID=i problem-file.txt /*#@ / { if ($2 == ID) { state = "printing" } else { state = } } !/^#@/ { il (state "printing") print $0 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
