Extract lines from output

Hi everyone,

I have the following string that repeats in a file.

I want to get the following output :

   "CDN_NF2_SGW_INT_443" 

   172.23.120.40:443 

   source-address-translation {
   pool /Common/SNAT_EXTERNAL_62.179.94.194

and parse the file till the end .

ltm virtual /Common/CDN_NF2_SGW_INT_443 {
    description "test"

   destination /Common/172.23.120.40:443
    ip-protocol tcp
    mask 255.255.255.255
    profiles {
        /Common/PFL_FL4 { }
    }
    rules {
        /Common/BASED_NODE_SELECT_FOR_L4
    }
    source 0.0.0.0/0
    source-address-translation {
        pool /Common/SNAT_EXTERNAL_62.179.94.194
        type snat
    }
    translate-address enabled
    translate-port enabled
    vlans {
        /Common/T3029.0
    }
    vlans-enabled

I run the following "

file.txt |grep -A3 'ltm virtual\| source-address-translation {' 

"

but the problem is not optimal. Thanks for the help.

Your code as posted will not work at all.

grep -A3 'pattern goes here' filename

Is the correct syntax.

Correct the order of elements in your command first. And then let's go from there. I do not understand your pattern, I guess you want alternation based on the use of the pipe symbol '\|'

Indeed I am not extracting solely what I need. the thing is I cannot use line numbers in my extraction script, since those might change, so I need to find patterns to look for.

so from this string :

ltm virtual /Common/CDN_NF2_SGW_INT_443 {     
      description "test"     
      destination /Common/172.23.120.40:443    
      ip-protocol tcp     mask 255.255.255.255    
      profiles {        
               /Common/PFL_FL4 { }     
      }     
      rules {         
              /Common/BASED_NODE_SELECT_FOR_L4    
     }     
     source 0.0.0.0/0     
     source-address-translation {         
             pool /Common/SNAT_EXTERNAL_62.179.94.194         
             type snat    
     }    
     translate-address enabled     
     translate-port enabled     
     vlans {         
             /Common/T3029.0     
     }     
    vlans-enabled

I need an output like this :

ltm virtual /Common/CDN_NF2_SGW_INT_443 {
destination /Common/172.23.120.40:443
source-address-translation {         pool /Common/SNAT_EXTERNAL_62.179.94.194

thanks!

Something like this (quick and dirty)?

# grep -E 'ltm virtual|source-address-translation|pool|destination' file
ltm virtual /Common/CDN_NF2_SGW_INT_443 {
   destination /Common/172.23.120.40:443
    source-address-translation {
        pool /Common/SNAT_EXTERNAL_62.179.94.194
Moderator comments were removed during original forum migration.

This topic was automatically closed 59 days after the last reply. New replies are no longer allowed.