in reply to Extracting specific text info from the config file ouput

If you insist on using a regex:
#!/usr/bin/perl -w use strict; while(<DATA>){ if(/\s+encryption key (\d+) size (\d+)bit \d+ (\S+)/){ print qq|$1\t$2\t$3\n|; } } 1; __DATA__ show run Building configuration... ! encryption key 1 size 40bit 7 621AA6093A25 transmit-key encryption key 2 size 40bit 7 7260637E4720 encryption key 3 size 40bit 7 0F733F116035 encryption key 4 size 40bit 7 03B71F3D601D encryption mode wep mandatory !

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re^2: Extracting specific text info from the config file ouput
by ramya2005 (Scribe) on Dec 16, 2005 at 23:16 UTC
    Great! The regular expression works fine for me. Thank you for the help!
Re^2: Extracting specific text info from the config file ouput
by ramya2005 (Scribe) on Dec 20, 2005 at 00:10 UTC
    I have a question which is an extension of the solution that I got for my previous problem. Extracting specific text info from the config file ouput
    I have a string as specified in the code below. I need a mechanisam to extract the authentication information.
    For me the right authentication information are
    1. authentication open <and/or followed by something>
    eg1: authentication open network-eap
    eg2: authentication open
    2. authentication shared <and/or followed by something>
    That means I should pick only the ones that start with authentication. Not the one starting with 'aaa' in the example below.
    Also when I am looping I should strip of the part which I extracted from the original string.

    Could some one tell me how to do it?
    my $str = "aaa authentication login\x0d\n ssid Rich\x0d\n authentic +ation open\x0d\n authentication shared \x0d\n"; my $authentication; while ($str =~/authentication (\S+)/){ $authentication = $authentiction. $1. " "; } # At the end of the while loop # $authentication should have the value # $authentication = open shared
    Any input provided will be much appreciated! Thanks.