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

Need some help with UNIX/Linux and awk scripting please: Consider the address bo

ID: 3796629 • Letter: N

Question

Need some help with UNIX/Linux and awk scripting please:

Consider the address book below:

$ cat addr

Xiao Li, lxiao, lxiao@unc.edu, 6705462234, Jackson, NC 764
Natkin William, wnatkin, wnatkin@imap28.vcu.edu, 8044344528, Richmond, VA 22345
Elizi Moe, emoe, emoe@ncsu.edu, 5208534566, Tempe, AZ 85282
Ma Ta, mta, mta@yahoo.com, 4345667345, Austin, TX 91030
Diana Cheng, dcheng, dcheng@asu.edu, 5203456789, Matitsi, WY 4587
Jackson Five, jfive, jfive@ncsu.edu, 5206564573, Kyenta, AZ 85483
Adi SrikanthReddy, sadi1, sadi1@imap1.asu.edu, 6578904566, Wyo, WS 67854

Write an awk script called activity6.1-6.awk to display the phone number of the user whose username is assigned to the variable user at the command line.

If we run the script as: awk –f activity6.1-6.awk user=mta addr The output should be:

The phone number for mta is 4345667345

Explanation / Answer

$ cat activity6.1-6.awk

BEGIN

{

read user

}

{

user = $2;

  number=$(grep "$user" addr | cut -d',' -f4)

}

END

{

print "The phone number of $user is $number."

}

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