For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2005 > Help with awk









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help with awk
Venu

2005-01-10, 8:03 am

Hi Everyone,

Need you help to improve on the script i have been using

Raw data:

Client: ssunnbu01
Backup ID: ssunnbu01_1105340684
Policy: Cat_Back
Sched Label: Daily
Schedule Type: FULL (0)
Retention Level: 1 year (8)
Backup Time: Mon Jan 10 2005 15:04:44 (1105340684)
Elapsed Time: 4496 second(s)
Expiration Time: Tue Jan 10 2006 15:04:44 (1136876684)
Kilobytes: 105878474
Number of Files: 409169
Keyword: CAT

Current Script:

BEGIN {OFS=","}

{if (match($0,"^Client:"))
{if (first==0)
first=1
else
print Client,BackupID,Policy,SchedLabel,Schedu
leType,RetentionLevel,BackupDate,BackupT
ime,ElapsedTime,ExpirationDate,Ex
pirationTime,Kilobytes,NumberofFiles,Key
word
Client=$2
BackupID=""
Policy=""
SchedLabel=""
ScheduleType=""
RetentionLevel=""
BackupTime=""
ElapsedTime=""
ExpirationTime=""
Kilobytes=""
Number_of_Files=""
Keyword=""}

if (match($0,"^Client:"))
Client=$2
if (match($0,"^Backup ID:"))
BackupID=$3
if (match($0,"^Policy:"))
Policy=$2
if (match($0,"^Sched Label:"))
SchedLabel=$3
if (match($0,"^Schedule Type:"))
ScheduleType=$3
if (match($0,"^Retention Level:"))
RetentionLevel=$3$4
if (match($0,"^Backup Time:"))
BackupDate=$5"-"$4"-"$6
if (match($0,"^Backup Time:"))
BackupTime=$7
if (match($0,"^Elapsed Time:"))
ElapsedTime=$3
if (match($0,"^Expiration Time:"))
ExpirationDate=$5"-"$4"-"$6
if (match($0,"^Expiration Time:"))
ExpirationTime=$7
if (match($0,"^Kilobytes:"))
Kilobytes=$2
if (match($0,"^Number of Files:"))
NumberofFiles=$4
if (match($0,"^Keyword:"))
Keyword=$2
}' $input > $output

New Raw Data:


Client: server1
Backup ID: server1_1105340684
Policy: Cat_Back
Sched Label: Daily
Schedule Type: FULL (0)
Retention Level: 1 year (8)
Backup Time: Mon Jan 10 2005 15:04:44 (1105340684)
Elapsed Time: 4496 second(s)
Expiration Time: Tue Jan 10 2006 15:04:44 (1136876684)
Kilobytes: 105878474
Number of Files: 409169
Keyword: CAT
ID: UT1565
ID: UT1610
ID: UT1617
ID: UT1619

As you can see new filed "ID" got added and also it is repeating. I added this new patern for matching but only the last occurance of the ID is getting printed where as i need every occurance to be printed and also the number of occurance can vary (min=1 to max= any). Hope you can help

Thanks
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com