Linux VM awk

CIT 371 Lab 11:  Regular Expressions and awk

Due date


Start your VM and log in as yourself. Open a terminal window and swtich to Student accoount. You will use the file ~Students/FILES/sales.txt for parts 1 and 2. cd to ~Student/FILES once logged in.



  1. Now we will use awk on the sales.txt file.
    1. We want to compute each employee’s monthly earnings, which is their sales * commission rate. We will output the sales person’s name, the month, and the amount. In awk, we reference the items by field number, so name is $2, month is $1, and the amount is $3*$4. We can write the awk statement as follows:

awk ‘{print $1, $2, $3*$4}’ sales.txt 

Notice that we have no condition here, just an action, because we want to compute this for all employees and months. Type in this instruction and run it. What is wrong with the output? To avoid outputting the first line of the file (which is a header line), we add the regex /[0-9]/ to indicate that we only want rows that have at least one number. We should also output the amounts with a $ preceding them. We do so by adding “$” before $3*$4. Revise the awk statement. What was your final instruction?

  1. Redo your command from 2a to compute only the sales for employees who worked in OH for the month and for each, they get a bonus of 5% (.05) added to their earnings. What command did you come up with? How different would your command be if you were outputting all employees and months but adding the 5% bonus for those who worked in OH?
  2. Write a single awk command using an if-else statement which will compute the sales amount for all employees but add a bonus of 10% for those who worked in at least four states. You can determine if an employee worked in four or more states in two ways. First, you can search for any line with at least 3 commas (the only use of the comma is to separate states). Or, you can test the variable NF, which stores the number of fields of the given row of the file. There are four fields other than the states, so to work at least 4 states, NF must be at least 8. What command did you come up with?
  3. In the textbook, we looked at how to compute the total salary for a single employee or the totals for multiple salaries. Here, compute and output the total salaries and the average per employee for the salesmen combined for January. What command did you come up with? Repeat this for all salesmen for the month of December (Dec). As there are no entries in the file, you should receive a total of 0. What was output for average? If you receive an error, use an if statement in the END clause to fix it. What command did you come up with?


  1. Just as we can pipe from ls or ps to egrep, we can also pipe from ls or ps to awk. Here you will pipe the results of ls –l operations to awk.
    1. We want to count the number of entries in /etc that are regular files (file type is -). We use a count variable to count each occurrence and an END statement to output the result in the variable similar to 2h. The solution is

ls –l /etc |

awk ‘/^-/ {count=count+1} END {print count}’ 

We could do something similar with egrep –c. How would you modify this statement to print each file name as well as obtain the count?

  1. We want to use awk to output all of the items in /etc that have more than 1 hard link. The link count is $2. What command did you come up with?
  2. Now, we want to use awk to sum up all of the file sizes of /etc and output the total and the average. We do not need a pattern, just an action block. The block will need two instructions, one to add to a sum the current item’s size ($5), and a second to increment a counter. Use an END statement to output the total, compute and output the average. What command did you come up with?
  3. Write a command to list all files in /dev whose owner and group are different. These items are $3 and $4 in the long listing. Print the entire row for any entries whose owner and group differ. What command did you come up with?
  4. Write a command to output the name of all devices in /dev that includes either sda or lp. What command did you come up with?
  5. Write a command to output the name of all devices that do not end with a digit. For instance, this should output vcs but not vcs1. What command did you come up with?
  6. Write a command to output the name of all files in /bin whose date is not listed as May. What command did you come up with?
  7. Write a command to output the name of all files in /bin that have an ‘s’ execution bit set for either user or group. What command did you come up with?


Close your terminal window and shut down your VM.





Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.