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!

Keeping Values While Parsing 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I wrote an awk script that lets me parse the file and print the first host name, but I can't figure out how to get it to display other hosts in the same policy.

BEGIN{printf ("%-28s %-10s %-30s %-15s %-30s %-38s %-15s\n", "Policy", "Active", "Client", "OS", "Schedule", "Type", "Policy Type\n=========================================================
========================================================================================================================")}
/^Policy Name/{policy = $3}
/Policy Type:/{ptype = $3}
/Active/{active = $2}
/HW\/OS\/Client:/{os = $(NF-1); client = $NF}
/ Schedule:/{schedule = $2}
/ Type:/{type = $2" "$3" "$4; printf ("%-28s %-10s %-30s %-15s %-30s %-38s %-15s\n", policy, active, client, os, schedule, type, ptype)}

I tried changing the HW/OS/Client line to the one below, but that doesn't help.

/HW\/OS\/Client:/,/Include:/{os = $(NF-1); client = $NF}

The resulting output is something like this:

test_policy yes client1 Windows2000 monthly_full Full Backup MS-Windows-NT
test_policy yes client1 Windows2000 Full Full Backup MS-Windows-NT
test_policy yes client1 Windows2000 Cumulative-Inc Cumulative Incremental Backup MS-Windows-NT
test_policy2 yes client3 Windows2008 monthly_full Full Backup MS-Windows-NT
test_policy2 yes client3 Windows2008 Full Full Backup MS-Windows-NT
test_policy2 yes client3 Windows2008 Differential Differential Incremental Backup MS-Windows-NT

The desired output is:

test_policy yes client1 Windows2000 monthly_full Full Backup MS-Windows-NT
test_policy yes client2 Windows2000 monthly_full Full Backup MS-Windows-NT
test_policy yes client1 Windows2000 Full Full Backup MS-Windows-NT
test_policy yes client2 Windows2000 Full Full Backup MS-Windows-NT
test_policy yes client1 Windows2000 Cumulative-Inc Cumulative Incremental Backup MS-Windows-NT
test_policy yes client2 Windows2000 Cumulative-Inc Cumulative Incremental Backup MS-Windows-NT
test_policy2 yes client3 Windows2008 monthly_full Full Backup MS-Windows-NT
test_policy2 yes client4 Windows2008 monthly_full Full Backup MS-Windows-NT
test_policy2 yes client3 Windows2008 Full Full Backup MS-Windows-NT
test_policy2 yes client4 Windows2008 Full Full Backup MS-Windows-NT
test_policy2 yes client3 Windows2008 Differential Differential Incremental Backup MS-Windows-NT
test_policy2 yes client4 Windows2008 Differential Differential Incremental Backup MS-Windows-NT

The input file looks like this:

Policy Name: test_policy

Policy Type: Standard
Active: yes
Effective date: 05/07/2003 11:58:43
Client Compress: no
Follow NFS Mounts: no
Cross Mount Points: no
Collect TIR info: no
Block Incremental: no
Mult. Data Streams: yes
Client Encrypt: no
Checkpoint: yes
Interval: 15
Policy Priority: 0
Max Jobs/Policy: Unlimited
Disaster Recovery: 0
Collect BMR info: no
Residence: Staging
Volume Pool: NetBackup
Server Group: *ANY*
Keyword: (none specified)
Data Classification: -
Residence is Storage Lifecycle Policy: no

Granular Restore Info: no
HW/OS/Client: Linux RedHat2.4 client1
Linux RedHat2.4 client2

Include: ALL_LOCAL_DRIVES

Schedule: full_backup
Type: Full Backup
Maximum MPX: 4
Synthetic: 0
PFI Recovery: 0
Retention Level: 1 (2 weeks)
Number Copies: 1
Fail on Error: 0
Residence: (specific storage unit not required)
Volume Pool: (same as policy volume pool)
Server Group: (same as specified for policy)
Calendar sched: Enabled
Allowed to retry after run day
Saturday, Week 2
Saturday, Week 3
Saturday, Week 4
Saturday, Week 5
Residence is Storage Lifecycle Policy: 0
Daily Windows:
Saturday 01:15:00 --> Sunday 01:15:00

Schedule: monthly_full
Type: Full Backup
Maximum MPX: 4
Synthetic: 0
PFI Recovery: 0
Retention Level: 1 (2 weeks) 10 (18 months)
Number Copies: 2
Fail on Error: 0 0
Residence: Staging quantum-lto5-i80
Volume Pool: NetBackup NetBackup
Server Group: *ANY* *ANY*
Calendar sched: Enabled
Saturday, Week 1
Residence is Storage Lifecycle Policy: 0
Daily Windows:
Saturday 00:00:00 --> Sunday 08:00:00

Schedule: Cumulative-Inc
Type: Differential Incremental Backup
Maximum MPX: 4
Synthetic: 0
PFI Recovery: 0
Retention Level: 1 (2 weeks)
Number Copies: 1
Fail on Error: 0
Residence: (specific storage unit not required)
Volume Pool: (same as policy volume pool)
Server Group: (same as specified for policy)
Calendar sched: Enabled
Allowed to retry after run day
Monday, Week 1
Tuesday, Week 1
Wednesday, Week 1
Thursday, Week 1
Monday, Week 2
Tuesday, Week 2
Wednesday, Week 2
Thursday, Week 2
Monday, Week 3
Tuesday, Week 3
Wednesday, Week 3
Thursday, Week 3
Monday, Week 4
Tuesday, Week 4
Wednesday, Week 4
Thursday, Week 4
Monday, Week 5
Tuesday, Week 5
Wednesday, Week 5
Thursday, Week 5
EXCLUDE DATE 0 - 02/25/2010
Residence is Storage Lifecycle Policy: 0
Daily Windows:
Monday 20:00:00 --> Tuesday 06:00:00
Tuesday 20:00:00 --> Wednesday 06:00:00
Wednesday 20:00:00 --> Thursday 06:00:00
Thursday 20:00:00 --> Friday 06:00:00

Policy Name: test_policy2

Policy Type: Standard
Active: yes
Effective date: 05/07/2003 11:58:43
Client Compress: no
Follow NFS Mounts: no
Cross Mount Points: no
Collect TIR info: no
Block Incremental: no
Mult. Data Streams: yes
Client Encrypt: no
Checkpoint: yes
Interval: 15
Policy Priority: 0
Max Jobs/Policy: Unlimited
Disaster Recovery: 0
Collect BMR info: no
Residence: Staging
Volume Pool: NetBackup
Server Group: *ANY*
Keyword: (none specified)
Data Classification: -
Residence is Storage Lifecycle Policy: no

Granular Restore Info: no
HW/OS/Client: Linux RedHat2.4 client3
Linux RedHat2.4 client4

Include: ALL_LOCAL_DRIVES

Schedule: full_backup
Type: Full Backup
Maximum MPX: 4
Synthetic: 0
PFI Recovery: 0
Retention Level: 1 (2 weeks)
Number Copies: 1
Fail on Error: 0
Residence: (specific storage unit not required)
Volume Pool: (same as policy volume pool)
Server Group: (same as specified for policy)
Calendar sched: Enabled
Allowed to retry after run day
Saturday, Week 2
Saturday, Week 3
Saturday, Week 4
Saturday, Week 5
Residence is Storage Lifecycle Policy: 0
Daily Windows:
Saturday 01:15:00 --> Sunday 01:15:00

Schedule: monthly_full
Type: Full Backup
Maximum MPX: 4
Synthetic: 0
PFI Recovery: 0
Retention Level: 1 (2 weeks) 10 (18 months)
Number Copies: 2
Fail on Error: 0 0
Residence: Staging quantum-lto5-i80
Volume Pool: NetBackup NetBackup
Server Group: *ANY* *ANY*
Calendar sched: Enabled
Saturday, Week 1
Residence is Storage Lifecycle Policy: 0
Daily Windows:
Saturday 00:00:00 --> Sunday 08:00:00

Schedule: Cumulative-Inc
Type: Differential Incremental Backup
Maximum MPX: 4
Synthetic: 0
PFI Recovery: 0
Retention Level: 1 (2 weeks)
Number Copies: 1
Fail on Error: 0
Residence: (specific storage unit not required)
Volume Pool: (same as policy volume pool)
Server Group: (same as specified for policy)
Calendar sched: Enabled
Allowed to retry after run day
Monday, Week 1
Tuesday, Week 1
Wednesday, Week 1
Thursday, Week 1
Monday, Week 2
Tuesday, Week 2
Wednesday, Week 2
Thursday, Week 2
Monday, Week 3
Tuesday, Week 3
Wednesday, Week 3
Thursday, Week 3
Monday, Week 4
Tuesday, Week 4
Wednesday, Week 4
Thursday, Week 4
Monday, Week 5
Tuesday, Week 5
Wednesday, Week 5
Thursday, Week 5
EXCLUDE DATE 0 - 02/25/2010
Residence is Storage Lifecycle Policy: 0
Daily Windows:
Monday 20:00:00 --> Tuesday 06:00:00
Tuesday 20:00:00 --> Wednesday 06:00:00
Wednesday 20:00:00 --> Thursday 06:00:00
Thursday 20:00:00 --> Friday 06:00:00


So to sum up the problem, I want to be able to display all of the clients in the policy and those clients should display the appropriate policy, schedule, etc.

I think my problem is just figuring out how to get it to loop before moving on to the next policy.

Any help would be greatly appreciated.

Thanks,

John
 
Hi

John said:
I tried changing the HW/OS/Client line to the one below, but that doesn't help.

/HW\/OS\/Client:/,/Include:/{os = $(NF-1); client = $NF}
Yepp, that is the way too begin changing it.
[ul]
[li]If the empty line after the HW\/OS\/Client section is always present, is easier to [highlight #fcc]use that as delimiter[/highlight].[/li]
[li]But anyway, you will have to [highlight #cfc]skip that empty line[/highlight] when processing.[/li]
[li]As you will need those values later, you have to [highlight #ccf]store them in arrays[/highlight].[/li]
[li]Then when printing out the data, [highlight #cff]loop over those arrays[/highlight] and [highlight #ffc]take the values from them[/highlight].[/li]
[li]And [highlight #fcf]empty the array[/highlight] after finished with a policy section.[/li]
[/ul]
Code:
[b]BEGIN[/b] [teal]{[/teal] [b]printf[/b] [teal]([/teal][green][i]"%-28s %-10s %-30s %-15s %-30s %-38s %-15s[/i][/green][lime][i]\n[/i][/lime][green][i]"[/i][/green][teal],[/teal] [green][i]"Policy"[/i][/green][teal],[/teal] [green][i]"Active"[/i][/green][teal],[/teal] [green][i]"Client"[/i][/green][teal],[/teal] [green][i]"OS"[/i][/green][teal],[/teal] [green][i]"Schedule"[/i][/green][teal],[/teal] [green][i]"Type"[/i][/green][teal],[/teal] [green][i]"Policy Type[/i][/green][lime][i]\n[/i][/lime][green][i]================================================================================================================================================================================="[/i][/green][teal])[/teal] [teal]}[/teal]
[fuchsia]/^Policy Name/[/fuchsia] [teal]{[/teal] policy [teal]=[/teal] [navy]$3[/navy][teal];[/teal] [highlight #fcf][navy]nrc[/navy][teal]=[/teal][purple]0[/purple][/highlight] [teal]}[/teal]
[fuchsia]/Policy Type:/[/fuchsia] [teal]{[/teal] ptype [teal]=[/teal] [navy]$3[/navy] [teal]}[/teal]
[fuchsia]/Active/[/fuchsia][teal]{[/teal] active [teal]=[/teal] [navy]$2[/navy] [teal]}[/teal]
[fuchsia]/HW\/[/fuchsia]OS[teal]\[/teal][fuchsia]/Client:/[/fuchsia][teal],[/teal][highlight #fcc][teal]![/teal]NF[/highlight] [teal]{[/teal] [highlight #cfc][b]if[/b] [teal]([/teal]NF[teal])[/teal][/highlight] [teal]{[/teal] os[highlight #ccf][teal][++[/teal]nrc[teal]][/teal][/highlight][teal]=[/teal][navy]$(NF-1)[/navy][teal];[/teal] client[highlight #ccf][teal][[/teal]nrc[teal]][/teal][/highlight][teal]=[/teal][navy]$NF[/navy] [teal]}[/teal] [teal]}[/teal]
[fuchsia]/  Schedule:/[/fuchsia] [teal]{[/teal] schedule [teal]=[/teal] [navy]$2[/navy] [teal]}[/teal]
[fuchsia]/    Type:/[/fuchsia] [teal]{[/teal] [b]type[/b] [teal]=[/teal] [navy]$2[/navy][green][i]" "[/i][/green][navy]$3[/navy][green][i]" "[/i][/green][navy]$4[/navy][teal];[/teal] [highlight #cff][b]for[/b] [teal]([/teal][navy]i[/navy][teal]=[/teal][purple]1[/purple][teal];[/teal]i[teal]<=[/teal]nrc[teal];[/teal]i[teal]++)[/teal][/highlight] [b]printf[/b] [teal]([/teal][green][i]"%-28s %-10s %-30s %-15s %-30s %-38s %-15s[/i][/green][lime][i]\n[/i][/lime][green][i]"[/i][/green][teal],[/teal] policy[teal],[/teal] active[teal],[/teal] client[highlight #ffc][teal][[/teal]i[teal]][/teal][/highlight][teal],[/teal] os[highlight #ffc][teal][[/teal]i[teal]][/teal][/highlight][teal],[/teal] schedule[teal],[/teal] [b]type[/b][teal],[/teal] ptype[teal])[/teal] [teal]}[/teal]
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].


Feherke.
 
feherke,

Thank you for your help. Have a star!

This seems to work perfectly.

I think I need to spend some more time learning about arrays.

Thanks,

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top