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

If you have a file called \'saved_data.txt\' with many lines of data, each line

ID: 3817339 • Letter: I

Question

If you have a file called 'saved_data.txt' with many lines of data, each line having values separated by a '$' character, how would you obtain the 7th value/field of each line using the cut command? Assume the same things from part (a), except now you want to obtain the 3rd character of the 5th value on each line. How would you do this using the cut command? If you have a file called 'records.csv' with several lines of data, each line containing comma-separated values, give the AWK command to print off the 5th number on each line (you have to tell AWK to use a comma as the separator using the -F flag, so look up this flag to see how to use it properly). Give the cut command for accomplishing the same thing that you did with AWK in part (c). Assume you want to read as input the file 'passwords.txt', change every lowercase letter to an uppercase letter and every '$' to a '#', then save the result back to that same file (overwriting it). How would you do this with the tr command?

Explanation / Answer

a. If you have a file called 'saved_data.txt' with many lines of data, each line having
values separated by a '$' character, how would you obtain the 7th value/field of each
line using the cut command?
cut -d $ -f 7 saved_data.txt
Cut with -d option will specify the delimiter, and -f will specify the field to pick.
So, the above command says to cut the 7th field, given the delimiter $
b. Assume the same things from part (a), except now you want to obtain the 3rd
character of the 5th value on each line. How would you do this using the cut
command? HINT: You may use piping here.
cut -d $ -f 5 saved_data.txt | cut -c 3
cut -d $ -f 5 will pick the 5th value of each line, and from that, value, we are
piping to another cut command, this time with -c option which specifies character
position 3, i.e., from the words picked in the first part, cut only the 3rd position.
c. If you have a file called records.csv, with several lines of data, each line containing
comma-separated values, give the AWK command to print off 5th number on each
line(you have have to tell AWK to use a comma as the field separator using -F flag).
awk -F ',' '{print $5}' records.csv   
-F specifies the field separator, and $5 will print the 5th field of every line.
d. Give the cut command for accomplishing the same thing that you did with AWK in part (c).
cut -d , -f 5 records.csv
will cut the 5th field separated by ,

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