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 paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Quality Papers

We value our clients. For this reason, we ensure that each paper is written carefully as per the instructions provided by the client. Our editing team also checks all the papers to ensure that they have been completed as per the expectations.

Professional Academic Writers

Over the years, our Acme Homework has managed to secure the most qualified, reliable and experienced team of writers. The company has also ensured continued training and development of the team members to ensure that it keep up with the rising Academic Trends.

Affordable Prices

Our prices are fairly priced in such a way that ensures affordability. Additionally, you can get a free price quotation by clicking on the "Place Order" button.

On-Time delivery

We pay strict attention on deadlines. For this reason, we ensure that all papers are submitted earlier, even before the deadline indicated by the customer. For this reason, the client can go through the work and review everything.

100% Originality

At Buy An Essay, all papers are plagiarism-free as they are written from scratch. We have taken strict measures to ensure that there is no similarity on all papers and that citations are included as per the standards set.

Customer Support 24/7

Our support team is readily available to provide any guidance/help on our platform at any time of the day/night. Feel free to contact us via the Chat window or support email:

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Buy An Essay has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.


Essay Writing Services

At Buy An Essay, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.


Admission and Business Papers

Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.


Editing and Proofreading

Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.


Technical papers

We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.