-1

This is a repost of my previous query which was well answered by Gerard,

search pattern pair using awk

Now I have another addition to this query, So here is my query.

Below is input string:

Policy Name:       KE15-LOCALHOST-APP-RADIX-DAILY

  Policy Type:         Standard
  Active:              yes
  Effective date:      05/06/2014 13:41:57
  Client Compress:     no
  Follow NFS Mounts:   no
  Cross Mount Points:  yes
  Collect TIR info:    no
  Block Incremental:   no
  Mult. Data Streams:  no
  Client Encrypt:      no
  Checkpoint:          yes
       Interval:       50
  Policy Priority:     0
  Max Jobs/Policy:     Unlimited
  Disaster Recovery:   0
  Collect BMR info:    no
  Residence:           KDNBACKUP01-HCART2-ROBOT-TLD-1
  Volume Pool:         UNIXFS
  Server Group:        *ANY*
  Keyword:             (none specified)
  Data Classification:       -
  Residence is Storage Lifecycle Policy:    no
  Application Discovery:      no
  Discovery Lifetime:      0 seconds
  ASC Application and attributes: (none defined)

  Granular Restore Info:  no
  Ignore Client Direct:  no
  Use Accelerator:  no
  HW/OS/Client:  Linux         RedHat2.6.18  172.23.1.63

  Include:  /appussd
            /home/ussd2ke
            /var/log
            /etc
            /usr

  Schedule:              Montlhy_Full
    Type:                Full Backup
    Calendar sched: Enabled
     Included Dates-----------
        Wednesday, Week 3
     Excluded Dates----------
        No specific exclude dates entered
        No exclude days of week entered
    Synthetic:           0
    Checksum Change Detection: 0
    PFI Recovery:        0
    Maximum MPX:         16
    Retention Level:     5 (3 months)
    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)
    Residence is Storage Lifecycle Policy:         0
    Daily Windows:
          Sunday     00:00:00  -->  Sunday     07:00:00
          Monday     00:00:00  -->  Monday     07:00:00
          Tuesday    00:00:00  -->  Tuesday    07:00:00
          Wednesday  00:00:00  -->  Wednesday  07:00:00
          Thursday   00:00:00  -->  Thursday   07:00:00
          Friday     00:00:00  -->  Friday     07:00:00
          Saturday   00:00:00  -->  Saturday   07:00:00

  Schedule:              Weekly_Full
    Type:                Full Backup
    Calendar sched: Enabled
     Included Dates-----------
        Wednesday, Week 1
        Wednesday, Week 2
        Wednesday, Week 4
        Wednesday, Week 5
     Excluded Dates----------
        No specific exclude dates entered
        No exclude days of week entered
    Synthetic:           0
    Checksum Change Detection: 0
    PFI Recovery:        0
    Maximum MPX:         16
    Retention Level:     3 (1 month)
    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)
    Residence is Storage Lifecycle Policy:         0
    Daily Windows:
          Wednesday  00:00:00  -->  Wednesday  10:00:00

  Schedule:              Daily_Inc
    Type:                Differential Incremental Backup
    Calendar sched: Enabled
     Included Dates-----------
        Sunday, Week 1
        Monday, Week 1
        Tuesday, Week 1
        Thursday, Week 1
        Friday, Week 1
        Saturday, Week 1
        Sunday, Week 2
        Monday, Week 2
        Tuesday, Week 2
        Thursday, Week 2
        Friday, Week 2
        Saturday, Week 2
        Sunday, Week 3
        Monday, Week 3
        Tuesday, Week 3
        Thursday, Week 3
        Friday, Week 3
        Saturday, Week 3
        Sunday, Week 4
        Monday, Week 4
        Tuesday, Week 4
        Thursday, Week 4
        Friday, Week 4
        Saturday, Week 4
        Sunday, Week 5
        Monday, Week 5
        Tuesday, Week 5
        Thursday, Week 5
        Friday, Week 5
        Saturday, Week 5
     Excluded Dates----------
        No specific exclude dates entered
        No exclude days of week entered
    PFI Recovery:        0
    Maximum MPX:         16
    Retention Level:     2 (3 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)
    Residence is Storage Lifecycle Policy:         0
    Daily Windows:
          Sunday     01:00:00  -->  Sunday     16:00:00
          Monday     01:00:00  -->  Monday     16:00:00
          Tuesday    01:00:00  -->  Tuesday    16:00:00
          Wednesday  01:00:00  -->  Wednesday  16:00:00
          Thursday   01:00:00  -->  Thursday   16:00:00
          Friday     01:00:00  -->  Friday     16:00:00
          Saturday   01:00:00  -->  Saturday   16:00:00

Desired output is:

Full Backup; Full Backup; Differential Incremental Backup, 00:00:00 --> 07:00:00; 00:00:00 --> 10:00:00; 01:00:00 --> 16:00:00; 3 months; 1 month; 3 weeks

Previous Output:

Full Backup; Full Backup; Differential Incremental Backup, 3 months; 1 month; 3 weeks

Previous Solution:

awk '
  BEGIN { SEP = "" }
  $1 == "Type:" { $1 = ""; T = T SEP $0 }
  $1 == "Retention" && $2 == "Level:" {
    sub(/^.*\(/," ")
    sub(/\).*/,"")
    L = L SEP $0
    if (SEP == "") {
      SEP = ";"
    }
  }
  END {
      sub(/^ */,"",T)
      print T "," L
  }'   $1

I have added daily window as well, in case there is nothing under "Daily Windows:" means a blank line, then echo "No Window"

Possible attempt, I am able to filter content between Daily Window and blank line, However I am not able to further filter out to display only unique time slot (not weekdays name and only unique time slot).

awk '
  BEGIN { SEP = "" }
  $1 == "Type:" { $1 = ""; T = T SEP $0 }
  $1 == "Retention" && $2 == "Level:" {
    sub(/^.*\(/," ")
    sub(/\).*/,"")
    L = L SEP $0
    if (SEP == "") {
      SEP = ";"
    }
  }
  /Daily Windows:/,/^$/ {
  sub(/^.*Daily.*/,"")
  sub(/^[^A-Z][a-z]+y$/,"")
  S = S SEP $0}
  END {
  sub(/^ */,"",T)
  print T "," L "," S
}'

Output still not upto the mark,

Automatic Full Backup; Application Backup; Automatic Full Backup; Application Backup; Automatic Full Backup; Application Backup, 1 year; 1 year; 1 month; 1 month; 3 weeks; 3 weeks,;;          Tuesday    00:00:00  -->  Tuesday    09:00:00;;;          Sunday     00:00:00  -->  Sunday     24:00:00;          Monday     00:00:00  -->  Monday     24:00:00;          Tuesday    00:00:00  -->  Tuesday    24:00:00;          Wednesday  00:00:00  -->  Wednesday  24:00:00;          Thursday   00:00:00  -->  Thursday   24:00:00;          Friday     00:00:00  -->  Friday     24:00:00;          Saturday   00:00:00  -->  Saturday   24:00:00;;;          Tuesday    00:00:00  -->  Tuesday    09:00:00;;;          Sunday     00:00:00  -->  Sunday     24:00:00;          Monday     00:00:00  -->  Monday     24:00:00;          Tuesday    00:00:00  -->  Tuesday    24:00:00;          Wednesday  00:00:00  -->  Wednesday  24:00:00;          Thursday   00:00:00  -->  Thursday   24:00:00;          Friday     00:00:00  -->  Friday     24:00:00;          Saturday   00:00:00  -->  Saturday   24:00:00;;;          Sunday     00:00:00  -->  Sunday     09:00:00;          Monday     00:00:00  -->  Monday     09:00:00;          Wednesday  00:00:00  -->  Wednesday  09:00:00;          Thursday   00:00:00  -->  Thursday   09:00:00;          Friday     00:00:00  -->  Friday     09:00:00;          Saturday   00:00:00  -->  Saturday   09:00:00;;;          Sunday     00:00:00  -->  Sunday     24:00:00;          Monday     00:00:00  -->  Monday     24:00:00;          Tuesday    00:00:00  -->  Tuesday    24:00:00;          Wednesday  00:00:00  -->  Wednesday  24:00:00;          Thursday   00:00:00  -->  Thursday   24:00:00;          Friday     00:00:00  -->  Friday     24:00:00;          Saturday   00:00:00  -->  Saturday   24:00:00;
  • What have you learned from the previous solution, and how have to applied that learning to this problem? – glenn jackman Mar 23 at 12:26
  • In your desired output, a) what is "00:00:00 --> 07:00:00"? (The first of the daily windows?), b) check the delimeters. – Gerard H. Pille Mar 24 at 23:31
  • Thanks for the comment, a) every pair of "Type:" and "Retention" will have "Daily Window:", I need the unique entries for each pair, in case there isn't any then echo "No Window". b) what should i check in delimeters – Sid Mar 25 at 10:31
  • I tried below code, but missing a lot, awk ' BEGIN { SEP = "" } $1 == "Type:" { $1 = ""; T = T SEP $0 } $1 == "Retention" && $2 == "Level:" { sub(/^.*\(/," ") sub(/\).*/,"") L = L SEP $0 if (SEP == "") { SEP = ";" } } /Daily Windows:/,/^$/ { S = S SEP $0 } END { sub(/^ */,"",T) print T "," S "," L }', but getting this output which is having days as well. – Sid Mar 25 at 10:48
  • delimeters: when do you want an comma, when a semi-colon? – Gerard H. Pille Mar 26 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.