This is for my Linux class. Consider the address book below: Consider the addres
ID: 3792383 • Letter: T
Question
This is for my Linux class. Consider the address book below:
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, Print the Last Name, First Name, Email Address, state and zip in a tabular format. Include the header identifying each field.
Explanation / Answer
Answer:
The following commands assume first column as first name and fourth column as last name.
Command in linux/unix:
awk 'BEGIN { FS = "," ; printf("Last Name First Name Email Address state zip ")} {printf("%s %s %s %s %s ", $4, $1, $2, $5, $3)}' input.csv
Command in Windows:
awk 'BEGIN { FS = "," ; printf("Last Name First Name Email Address state zip ")} {printf("%s %s %s %s %s ", $4, $1, $2, $5, $3)}' input.csv
If first column is last name and fourth column as first name then the commands are as follows:
Command in linux/unix:
awk 'BEGIN { FS = "," ; printf("Last Name First Name Email Address state zip ")} {printf("%s %s %s %s %s ", $1, $4, $2, $5, $3)}' input.csv
Command in Windows:
awk 'BEGIN { FS = "," ; printf("Last Name First Name Email Address state zip ")} {printf("%s %s %s %s %s ", $1, $4, $2, $5, $3)}' input.csv
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.