Write a bash shell script to carry out each of the following tasks: b. Pretty-Pr
ID: 3826374 • Letter: W
Question
Write a bash shell script to carry out each of the following tasks:
b. Pretty-Printing a Data File:
Some database and spreadsheet packages can save-files with comma-separated values, (CSVs) as one way to export their data, so other applications can import them for further processing. Given a data file with comma-separated fields, of the form:
Write a shell script to reformat the data and print it out to “stdout” in labeled, evenly-spaced columns as the following example, note the lengths of the label strings in the first line and the maximum string length in each column:
Full Name Street Address City State z ip, Phone Number Column labels Jones, Bill, 235 S. Williams St., Denver, CO, 80221, (303) 244-7989 Data line Data line Smith, Tom, 404 Polk Ave., Los Angeles, CA, 90003, (213) 879-5612Explanation / Answer
#!/usr/bin/ksh
#abc.csv is the filename of csv file
cat abc.csv | nawk 'BEGIN{
FS=","
}
{
printf("%10s %20s%20s%20s%20s%20s ",$1,$2,$3,$4,$5,$6);
}' | awk -v n=2 -v s="---------- --------------- ----- ------ ---- ---------------" 'NR == n {print s} {print}'
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.