procura par de padrões usando awk

0

Estou procurando uma solução para encontrar o par de padrões de pesquisa.

awk '/Schedule:/,/Retention Level:/' /tmp/data
  Schedule:              Full
    Type:                Full Backup
    Calendar sched: Enabled
     Included Dates-----------
        Tuesday, Week 1
        Tuesday, Week 2
        Tuesday, Week 3
        Tuesday, Week 4
        Tuesday, 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:         4
    Retention Level:     2 (3 weeks)
  Schedule:              INC
    Type:                Differential Incremental Backup
    Calendar sched: Enabled
     Included Dates-----------
        Sunday, Week 1
        Monday, Week 1
        Wednesday, Week 1
        Thursday, Week 1
        Friday, Week 1
        Saturday, Week 1
        Sunday, Week 2
        Monday, Week 2
        Wednesday, Week 2
        Thursday, Week 2
        Friday, Week 2
        Saturday, Week 2
        Sunday, Week 3
        Monday, Week 3
        Wednesday, Week 3
        Thursday, Week 3
        Friday, Week 3
        Saturday, Week 3
        Sunday, Week 4
        Monday, Week 4
        Wednesday, Week 4
        Thursday, Week 4
        Friday, Week 4
        Saturday, Week 4
        Sunday, Week 5
        Monday, Week 5
        Wednesday, 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:         4
    Retention Level:     2 (3 weeks)

Acima é a entrada

A saída desejada é

Full Backup;Differential Incremental Backup , 3 weeks;3 weeks

Qual é o par de tipo e nível de retenção. Então, em cada tipo: existe um nível de retenção. Eu preciso de todos os pares na saída desejada.

Arquivo de entrada adicional no qual mais de dois pares de tipo e retenção estão disponíveis:

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: 4 Retention Level: 5 (3 months) 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: 4 Retention Level: 3 (1 month) 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: 4 Retention Level: 2 (3 weeks)

    
por Sid 28.08.2018 / 09:23

2 respostas

2

Este script:

awk '
  $1 == "Schedule:" { $1 = ""; S = $0 }
  $1 == "Type:" { $1 = ""; T = $0 }
  $1 == "Retention" && $2 == "Level:" {
    sub(/^.*\(/,"")
    sub(/\).*/,"")
    print S ", " T ", " $0
  }' \
  $1

produz

 Full,  Full Backup, 3 weeks
 INC,  Differential Incremental Backup, 3 weeks

Este aqui

awk '
  BEGIN { SEP = "" }
  # if line starts with 'Type:', remove that label,
  # add separator and remainder of line to T
  $1 == "Type:" { $1 = ""; T = T SEP $0 }
  # Retention level lines, add only what's between
  # brackets to L, set separator to ";"
  $1 == "Retention" && $2 == "Level:" {
    sub(/^.*\(/," ")
    sub(/\).*/,"")
    L = L SEP $0
    if (SEP == "") {
      SEP = ";"
    }
  }
  END {
      sub(/^ */,"",T)
      print T "," L
  }' \
  $1

produz

Full Backup; Full Backup; Differential Incremental Backup, 3 months; 1 month; 3 weeks
    
por 28.08.2018 / 10:16
0

Tente também

awk -F"[:)(]" '/Schedule:/,/Retention Level:/ {if (/Type/) printf "%s, ", $NF; if (/Retention/) print $(NF-1)}' /tmp/data
                Full Backup, 3 weeks
                Differential Incremental Backup, 3 weeks

EDITAR: ou

 awk -F"[:)(]" '/Schedule:/,/Retention Level:/ {if (/Type/) TYP = TYP ";" $NF; if (/Retention/) RET = RET ";" $(NF-1)} END {gsub (/; */, ";", TYP); print substr (TYP, 2) "," substr (RET, 2)}' /tmp/data
Full Backup;Differential Incremental Backup,3 weeks;3 weeks
    
por 28.08.2018 / 11:20