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

Linux Question: The next couple questions deal with the file \"last_log\". Take

ID: 3804128 • Letter: L

Question

Linux Question:

The next couple questions deal with the file "last_log". Take a look at it if you like, it is just the output of a command called "last". It is in that same directory as before, and you can use it there or copy it if you like. I have seen some suspicious activity from IP addresses that start with 68.99. In the file they will be listed as "68-99-" or as "ip68-99-" and they may have *.om" on the end. (These are Cox users in Omaha. For the correct answer you will need to figure out how to eliminate the extra junk and just use the IP address.) I want you to create one command that will give me a sorted list of these suspicious users in the following format: adammuno 68-99-4-45 ajgehrin 68-99-5-15 (snlp - many are cut out) wmahoney 68-99-3-88 zfaulkne 68-99-28-102 Cool, eh? You may need to use - I know because I had to figure it out - the combination of "grep", "sed" (with multiple -e options), "awk", "sort", and "uniq". The correct output should have 32 people that match. What did you come up with?

Explanation / Answer

Please try following command :

awk '{ if ( match($3, /^68-99-/) || match($3, /^ip68-99-/)) print $1 " " $3}' last_log | sort -k1 | uniq

I am using a linux system and it works for me , please comment if some of the options of awk is not supported on your machine.

The way ablove command works is . awk command reads each line in the file "last_log" one by one, matches the third column of each line with a string which starts either with "68-99-" or "ip68-99-" . awk by default assumes ' ' (space) as a delimiter. The sort command sorts the output of awk according to first column i.e the name of the user. uniq command just removes the duplicate lines from the output of sort 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