This is for my linux class and please use the \"awk\" editor. Consider the addre
ID: 3795623 • Letter: T
Question
This is for my linux class and please use the "awk" editor.
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 a 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 your script as: awk –f activity6.1-6.awk user=mta addr
The output should be:
The phone number for mta is 4345667345
Explanation / Answer
Syntax for AWK
awk [ -F fs ] [ -v var=value ] [ 'prog' | -f progfile ] [ file ... ]
-F fs - >Sets the input field separator to the regular expression fs.
-v var = value - > Assigns the value value to the variable var before executing the awk program.
'prog' - > An awk program.
-f progfile - > Specify a file, progfile, which contains the awk program to be executed.
file - > A file to be processed by the specified awk program.
awk -F',' '{printf "%-30s|%-30s|%-20s ",$1,$2,$3,$4,$5}' addr.txt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.