Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Field Separators in Certain Fields of an Awk Script

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I have the following awk script which works well for the most part, but when the first field, client, contains client.domain.com, I would just like to display the client portion. I would also like to modify the elapsed time so that it does not display leading zero's (if hhh:mm:ss is equal to 000:04:23 I would only like to display m:ss). Sample output and desired output are shown below.

BEGIN {printf ("%-25s %-9s %-l6s %12s %-11s %-10s\n" ,
"Client", "Date", "Time", "Elapsed Time", "Total MB", "# of Files");print "==============================================================================="}
/^Client:/{client = $2}
/^Backup Time:/{date = $3; time = $4}
/^Elapsed Time:/{elapsed = $3}
/^Kilobytes:/{$2=$2/1024; MB = $2}
/^Number of Files:/{files = $4; printf ("%-25s %-9s %-6s %-12s %-11.0f %-10s\n", client, date, time, elapsed, MB, files)}

Sample Output:

Client Date Time Elapsed Time Total MB # of Files
====================================================================
client.dom.com 09/08/2003 05:12:27 000:04:29 62 60
client2.dom.com 09/07/2003 08:17:07 023:04:29 462 600
Desired Output:

Client Date Time Elapsed Time Total MB # of Files
============================================================
client 09/08/2003 05:12:27 04:29 62 60
client2 09/08/2003 08:17:07 23:04:29 462 600

Any help would be greatly appreciated.

Thanks,

John
 
pls, post input.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Input:

Client: ccure
Backup ID: ccure_1063012347
Class: ccure
Class Type: Standard
Sched Label: cumulative_backup
Schedule Type: Cumulative Incremental Backup
Retention Level: 1 month (3)
Backup Time: 09/08/2003 05:12:27
Elapsed Time: 000:04:29
Expiration Time: 10/09/2003 05:12:27
Compressed: no
Encrypted: no
Kilobytes: 63600
Number of Files: 60
Primary Copy: 1
Image Type: 0 (Regular)
Keyword: (none specified)
Ext Security Info: no
File Restore Raw: no
Image Dump Level: 0
File System Only: no
Object Descriptor: (none specified)
Multiplexed: no
TIR Available: no
 
BEGIN {printf (&quot;%-25s %-9s %-l6s %12s %-11s %-10s\n&quot; ,
&quot;Client&quot;, &quot;Date&quot;, &quot;Time&quot;, &quot;Elapsed Time&quot;, &quot;Total MB&quot;, &quot;# of Files&quot;);print &quot;===============================================================================&quot;}
/^Client:/{client = index($2, &quot;.&quot;) ? substr($2, 1, index($2, &quot;.&quot;)-1) : $2;}
/^Backup Time:/{date = $3; time = $4}
/^Elapsed Time:/{elapsed = $3}
/^Kilobytes:/{$2=$2/1024; MB = $2}
/^Number of Files:/{files = $4; printf (&quot;%-25s %-9s %-6s %-12s %-11.0f %-10s\n&quot;, client, date, doDate(time), doDate(elapsed), MB, files)}


function doDate(d, i,numD, DA, outD)
{
outD=&quot;&quot;;
numD=split(d, DA, &quot;:&quot;);
for(i=1; i <= numD; i++) {
gsub(/^[0]+/, &quot;&quot;, DA)
if ( DA != &quot;&quot;)
outD= (i != 1 && length(outD)) ? outD &quot;:&quot; DA : DA;
}
return outD;
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks Vlad!! That works well, but for some reason, the columns are not aligning properly. Below is an example of the output.

sunprodd 09/06/2003 2:38:21 2:23:42 66618 4921
sunprode 09/07/2003 4:14:37 7:27 303 904
sunprode 09/06/2003 23:58:11 7:52:22 31626 417082
sunweba 09/05/2003 22:1:34 5:17:41 45428 641930
sysmgt 09/08/2003 2:28:27 4:13 1 7
sysmgt 09/08/2003 1:12:21 1:14:3 260 235

Thanks,

John
 
And with this format ?
Code:
printf &quot;%-25s %9s %6s %12s %11.0f %10s\n&quot;, client, date, time, doDate(elapsed), MB, files

Hope This Help
PH.
 
Or stick some tabs inbetween each field :
printf &quot;%-25s\t%9s\t%6s\t%12s\t%11.0f\t%10s\n&quot;, etc etc

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top