Issue
I have a csv file with following content.
"TELUS","Vancouver Canada","67.151","0.325","0","63247942","64210661","768241424","858087937"
"TELUS","Vancouver Canada","7.151","0.325","0","63247942","64210661","768241424","858087937"
With the help of awk, I have successfully parsing them to readable format.
awk -F, '{gsub(/"/, ""); printf "| %-11s | %-17s | %.1f %-6s | %.1f %-6s | %.1f %-6s | %.1f %-5.16s |\n", $1, $2, $7/125000, "MB/s", $6/125000, "MB/s", ($8+$9)/(1000*1000*1000), "GB", $3, "ms" }'
Return this
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 67.2 ms |
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 7.2 ms |
But as you can see the space is not equal on latency field. I want it to be like this.
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 67.2 ms |
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 7.2 ms |
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 947.2 ms |
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 7241.2 ms |
I'm putting two extra field at above, the point is I want to keep the column spacing intact no matter how large the latency is. How to do this?
Solution
try { %9.3f %-3.16s
}:
echo "${a}" | mawk '{ gsub(/[\42]/,"")
printf "| %-11s | %-17s | %.1f %-6s | %.1f %-6s "\
"| %.1f %-6s | %9.3f %-3.16s |\n",\
$1 , $2,
$7 * 8E-6 , "MB/s",\
$6 * 8E-6 , "MB/s", \
($8+$9)*(1E-9), "GB" , $3, "ms" }' FS=','
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 67.151 ms |
| TELUS | Vancouver Canada | 513.7 MB/s | 506.0 MB/s | 1.6 GB | 7.151 ms |
Answered By - RARE Kpop Manifesto Answer Checked By - Cary Denson (WPSolving Admin)