This is for my Linux class. Consider the address book below:
Consider the address book below:
$ cat addr
Xiao Li, [email protected], 6705462234, Jackson, NC 764
Natkin William, [email protected], 8044344528, Richmond, VA 22345
Elizi Moe, [email protected], 5208534566, Tempe, AZ 85282
Ma Ta, [email protected], 4345667345, Austin, TX 91030
Diana Cheng, [email protected], 5203456789, Matitsi, WY 4587
Jackson Five, [email protected], 5206564573, Kyenta, AZ 85483
Adi SrikanthReddy, [email protected], 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.
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\n")} {printf("%s %s %s %s %s\n", $4, $1, $2, $5, $3)}' input.csv
Command in Windows:
awk 'BEGIN { FS = \",\" ; printf(\"Last Name First Name Email Address state zip\n\")} {printf(\"%s %s %s %s %s\n\", $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\n")} {printf("%s %s %s %s %s\n", $1, $4, $2, $5, $3)}' input.csv
Command in Windows:
awk 'BEGIN { FS = \",\" ; printf(\"Last Name First Name Email Address state zip\n\")} {printf(\"%s %s %s %s %s\n\", $1, $4, $2, $5, $3)}' input.csv
Get Answers For Free
Most questions answered within 1 hours.