mardi 22 novembre 2016

Sed deleting content between 2 patterns if they are less than n lines

i've been searching for a while but i dont find how to make it:

i have a file that contains a lot of things + the following informations:

pool_1: &pool_prod
        - ip: 10.1.60.5
          weight: 1
        - ip: 10.1.60.6
          weight: 1

    pool_prod_nl: &pool_prod_nl
        - ip: 10.1.60.47
          weight: 1

    pool_prod_it: &pool_prod_it
        - ip: 10.1.60.65
          weight: 1
        - ip: 10.1.60.83
          weight: 1

    pool_prod_it: &pool_prod_dek
        - ip: 10.1.60.68
          weight: 1


I'd like to keep the result:

pool_1: &pool_prod
    - ip: 10.1.60.5
      weight: 1
    - ip: 10.1.60.6
      weight: 1

pool_prod_it: &pool_prod_it
        - ip: 10.1.60.65
      weight: 1
    - ip: 10.1.60.83
      weight: 1

When i do

sed -n '/pool_/,/^$/{p; /^$/q}'

i can extract some informations that i listed on the first code but i dont succes to filter them more because they have the same patterns and infos between, just the number of lines or the number of occurence inside can make a difference, but i dont find how to make it.

I'll appreciate any help thanks in advance

Aucun commentaire:

Enregistrer un commentaire