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

Some assistance with Linux/UNIX and using the awk command would be greatly appre

ID: 3792795 • Letter: S

Question

Some assistance with Linux/UNIX and using the awk command would be greatly appreciated!

Consider the address book below:

$ cat addr

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

Using the awk command, please show the command and how you would Print the Last Name, First Name, Email Address, state and zip in a tabular format. Include the header identifying each field.

Explanation / Answer

Hello, this is the solution, i have tested it out too.

awk 'BEGIN { format = "%-15s %-18s %-25s %-10s %s %s "

   printf format, "firstName", "Lastname", "EmailId", "State","Zip",""

   printf format, "---------", "--------", "--------","-------","--------","" }

   { printf format, $1, $2, $3, $5, $6,$7}' addr.txt | tr -d ,

ok lets start with awk, firtsly for formating declared a constant, first is %-15s which says left alinged,15 charaters similarly for other. the first printf prints the header of table.

second printf prints data. I have used tr -d , to remove the ", " from the printed data, since delimation in your file is not consistant, i was not able to use field seperator.

Here is the output:

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