in reply to just another search program

It appears from the example that the 'Network name' is a header, and are multiple 'Interface records', but it's not clear whether there could be multiple Network Name/Interface groups per file? The following assumes not.

It would also appear that could be more than one "address above Monitored circuit.", going by the "Number of addresses" field. I don't think either of the other solutions would cater for that? If so, this might be useful. I've also captured and output the Number of IPs value, but that is easily removed or discarded.

You'll note that this makes no attempt to verify the format or legality of the ip addresses whilst parsing the file, simply treating them as whitespace delimited tokens. If you need to verify the addresses, that is better done as a separate step.

#! perl -slw use strict; my( $nName, $iName, $vrid, $state, $paddr, $nAddr, $oAddrs, @oAddrs ); die "File does not contain a Network name header" unless ( $nName ) = <DATA> =~ m[Network\sname \s+ (\S+)]x; local $/ = "\nI"; while( <DATA> ) { if( ( $iName, $vrid, $state, $paddr, $nAddr, $oAddrs ) = m[ (?=.*? nterface \s+ (\S+) ) (?=.*? VRID \s+ (\S+) ) (?=.*? State: \s+ (\S+) ) (?=.*? Primary\saddress: \s+ (\S+) ) (?=.*? Number\saddresses: \s+ (\S+) ( .+? ) (?=Monitored\scircuits:) ) ]smx ) { @oAddrs = split ' ', $oAddrs; print join ', ', $nName, $iName, $vrid, $state, $paddr, $nAddr +, @oAddrs; } else { warn "File did not match required format"; } }

Output

C:\test>junk1 A, WEB_A, 145, Master, 194.551.205.250, 1, 135.51.045.242 A, WEB_B, 145, backup, 19.51.205.20, 2, 135.51.05.22, 321.654.987.111 A, WEB_C, 145, backup, 19.51.205.20, 3, 135.51.05.22, 123.456.789.001, + 321.654.987.111

Extended dataset

__DATA__ Network name A Interface WEB_A ggggggggg VRID 145 State: Master XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 194.551.205.250 Number addresses: 1 135.51.045.242 Monitored circuits: vbgghdfgdfg Interface WEB_B ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 2 135.51.05.22 321.654.987.111 Monitored circuits: vbgghdfgdfg Interface WEB_C ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 3 135.51.05.22 123.456.789.001 321.654.987.111 Monitored circuits: vbgghdfgdfg

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: just another search program
by sunny (Initiate) on Feb 13, 2006 at 10:54 UTC
    Hi

    when there is multiple network the code does print each of the network name ?

    Any clues ?

      Maybe you missed the bit where I said

      but it's not clear whether there could be multiple Network Name/Interface groups per file? The following assumes not.

      If there are multiple 'Network name'/'Interface name' groups in each file, then you could adapt my solution with an extra outer loop, but you would probably be better to use one of the other solutions.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        hello
        #use strict; #use warnings; $/=undef; $d=<DATA>; print " Hello\n"; print if $d=~ /Device |interface |VRID|state|primary address/i; my (@ip)=($d=~m/number addresses(?:.*?)((?:\d{1,3}\.){3}\d{1,3})/gsi); print "The addresses are: ". join("\n",@ip)."\n"; __DATA__ logging to Device F01 is 19.9.16.11... Showing the vrrp status VRRP Interfaces Interface WEB_A Authentication: NoAuthentication VRID 39 State: Master Time since transition: 582693 hfghfghfghghghfghfhhfgh Primary address: 195.51.205.220 Number addresses: 1 195.51.205.222 Monitored circuits: Afgh_A (priority 1fgh50) SRghf1 (priority 1fgh50) Interface DATA_DL Nufghfghmber of vhfghl roufgh Fgfhfghs: AuthefghfgntichoAhfhication VRID 2556 State: Master Time since transition: 13405375 Bahfgh Flafghfghgs: Advertfghdl: 1 Rfghfghfgval: 3fghfghfgh fghfsgh VfghfghVRghfg Vh Primary address: 19.18.27.65 Next advertisement: 0 Number addresses: 1 15.12.57.234 I logging to Device L2 is 14.359.1.2... Showing the vrrp status VRRP Interfaces Interface SDC_A Nughujgj AuthentijghjghjNoAuthentication VRID 9 State: Backup Time since transition: 582695 Mghjghjer: hgjghjghj0 BahhjFlags: Adverghjad Interval: 3 VMAChj VMAhj1:ef Primary address: 195.51.205.221 Masghjghjg Number addresses: 1 195.51.205.222 Interface SA Numbehgjghjr of virtualj: 1 Fghjg Authentijghjtion VRID 7 State: Backup Time since transition: 582695 Master: 62.187.224.12 Baseghjghj4 Flags: Advertisement ihjghjRouterhjghj3jghjVRRP VMAC: ghj:01jghj Primary address: 62.187.224.13 Mastghjghj Number addresses: 1 6.17.26.14
        this code just prints only the IP Address below the "number address". it doesnt't print the Device name,interface name,VRID,State,Primary address.

        whats wrong in it ?
        hi

        can you just add up a loop ? its not working for me ?