Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give AWK commands for accomplishing each of the following: Print the 2nd last fi

ID: 3817325 • Letter: G

Question

Give AWK commands for accomplishing each of the following: Print the 2nd last field (the field directly before the last field) of each line from a file named 'last.txt' Assume you have a file called 'names' that contains a list of people, one person per line. Also, assume that on each line the 3rd field on that line contains the age of the person. Some of the people do not have an age listed, and those lines only have 1 field. Print the total age for all the people that have an age (the sum of all of their ages). Print the total number of lines from a file named 'lines' Exchange the first and the third fields of every line, and then print the lines (you can print each line directly after the exchange). After printing all of the lines, print out the message "Done!". Assume the file name is 'switch txt'.

Explanation / Answer

Please give the thumbs up, if it is helpful for you. Thank you!!

Ans c)

Print the second last field of each line in the file:

The sum of all ages:

Total number of lines in the file:

In general, wc -l <filename> will give total number of lines in the file. If you want to do this using awk, use

If you only want to use awk, do

swap first and third column:

awk -F, '{ print $3 "\" $1 }' switch.txt

also can be done using sed command:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote