AWK Scripting

Homework Assignment – AWK

  1. Consider the file cars provided. The columns in the file contain from left to right: the car’s make, model, year of manufacture, mileage, and price

 

  • Print only the lines with the string chevy.
  • Print the year of manufacture, price, mileage, and model of all the ford cars

 

 

  1. Consider the file cars provided. The columns in the file contain from left to right: the car’s make, model, year of manufacture, mileage, and price

 

  • Print the year of manufacture, price, mileage, and model of all the ford cars in a csv format.

 

 

  1. Consider the file cars provided. The columns in the file contain from left to right: the car’s make, model, year of manufacture, mileage, and price

 

  • Write a script to print the year of manufacture, price, mileage, and model of all the ford cars in a csv format. Be sure to use multi-line statements for improved readability. Include the header identifying each field, and a footer indicating the end of listing.

 

 

 

  1. Consider the file cars provided. The columns in the file contain from left to right: the car’s make, model, year of manufacture, mileage, and price

 

  • Write an awk script that displays the year of manufacture, price, mileage, and model of all the cars priced at or less than $3,000. Below is a report format example:

Cars costing at most $3,000

Year                 Price                Mileage            Model

——                 ——-               ———-            ———

1970                $2500              73                    fury

END OF THE LISTING

 

 

  1. Consider the file cars provided. The columns in the file contain from left to right: the car’s make, model, year of manufacture, mileage, and price

 

  • Write an awk script that displays each car make, model, and price as below:

<car1 make>(<car1 model>), <car1 price>; <car2 make>(<car2 model>), <car2 price>; <car3 make>(<car3 model>), <car3 price>; etc.

 

 

  1. Consider the file dna.txt provided. As you can tell, it is quite a big file. The number of columns is different from one record to another.

 

  • Write an awk script that prints the number of columns for each row before the entire row. And the total number of records. Your output should have the following format:

<number of fields>; <entire row1>

<number of fields>; <entire row2>

Total Number of records: <number of records>

 

 

  1. Consider the file etcpasswd.txt provided. It has the structure

Username:Password:UserID:GroupID:Comments:HomeDirectory:LoginShell

 

  • Write aawk script that displays the username, home directory, and login shell of users who do not have password.

The output should look like (ensure proper alignments):

The following users do not have password

<username>     <Home Directory>       Login shell

 

 

  1. Below are the student grades for each class component:

$ cat score

pchen72  50 71 55 93 115

jmaszk   45 76 49 88 102

bvbui    59 78 53 96 145

mtcrowle 33 65 39 82 100

mrchave3 54 77 56 98 158

 

  • Write a awk script called for_loop.awk that compute the final percentage score for each student, as well as the class average

The max score is 450 and should be set in the BEGIN block

The output should be (round the score to nearest integer):

Total number of records: 5

Final score for pchen72 =  85.33%

Final score for jmaszk=  80%

Class Average =  86.1%

The header line should show: Final Score computation

 

 

  1. Redo previous activity using the while-loop

$ cat score

pchen72  50 71 55 93 115

jmaszk   45 76 49 88 102

bvbui    59 78 53 96 145

mtcrowle 33 65 39 82 100

mrchave3 54 77 56 98 158

 

  • Write a awk script called while.awk that compute the final percentage score for each student, as well as the class average

The max score is 450 and should be set in the BEGIN block

The output should be (round the score to nearest integer):

Total number of records: 5

Final score for pchen72 =  85%

Final score for jmaszk=  80%

Class Average =  86%

The header line should show: Final Score computation

 

 

  1. Exercise 12.17 page 357

 

 

 

 

Last Updated on February 11, 2019

Don`t copy text!
Scroll to Top