I am a beginner in shell scripting. Just made 1 script with the help of others and it is working like we expected. However i want to organize it more.
Current Script
{ date '+%F %T'; "$ipath"/cli iedge list | awk 'BEGIN { print "Registration ID", "Ongoing Calls"} /Registration ID/ { id = $3; next } /Ongoing Calls/ { print id,$3 }' } >> "$ifile"
Output which is coming as below
- Registration ID Ongoing Calls
- Nitin_03 30
- Nitin_01 0
- Registration ID Ongoing Calls
I want the output should come like as below.
------------------------------------- |Registration ID | Ongoing Calls | ------------------------------------- | Nitin_03 | 30 | ------------------------------------- | Nitin_01 | 0 | -------------------------------------
Can anyone please help me on this.
Here is the change and its working fine only thing when i added another "character" it is giving fatal error.I am getting error when i added "maxCallsOut" as you can see below
ipath=/usr/local/nextone/bin ifile=/root/Nick.csv "$ipath"/cli igrp list | awk ' BEGIN { print "------------------------------------"; printf "|%-17s|%-16s|%-15s|\n","Iedge Group", "maxCallsIn"
"maxCallsOut" } /Iedge Group/ { id = $3; next } /maxCallsIn/ /maxCallsOut/{print "------------------------------------"; printf
"|%-17s|%-16s|%-15s\n",id,$3 } END{ print "------------------------------------"; }'
------------------------------------ awk: cmd. line:3: fatal: not enough arguments to satisfy format string `|%-17s|%-16s|%-15s| ' ^ ran out for this one
printf id,$3
. The corresponding equation in my code isprintf "|%-17s|%-16s|\n",id,$3
which is very different. Please check my answer again. – John1024 Jun 3 at 0:24printf "|%-17s|%-16s|%-15s\n",id,$3
The reason for the error is that you added a third format string but did not add a third variable. The number of format strings and the number of variables need to match. – John1024 Jun 3 at 0:37