Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

difficulties on AWK parsing/passing/variables

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
0
0
US
Hey all, need some assistance on this one. Greets to all and thanks in advance (long time no post)...

So I have the following in a file
Code:
term permit_database_access {
    from {
        source-address {
            aaa.aaa.aaa.aaa/32;
            bbb.bbb.bbb.bbb/32;
            ccc.ccc.ccc.ccc/32;
            ddd.ddd.ddd.ddd/26;
            eee.eee.eee.eee/32;
            fff.fff.fff.fff/32;
            ggg.ggg.ggg.ggg/32;
        }
        destination-port 12345;
    }
    then accept;

But another instance might be

Code:
term permit_other_database_access {
    from {
        source-address {
            aaa.aaa.aaa.aaa/32;
            bbb.bbb.bbb.bbb/32;
            ccc.ccc.ccc.ccc/32;
        }
        destination-port 12345;
    }
    then accept;

And I need this to print out this:

Code:
ip access-list extended permit-other-database-access
permit aaa.aaa.aaa.aaa/32 any 12345
For each source address... Anyone care to help... This is what I started with...

Code:
rulename=$(awk '/term/{gsub(/_/, "-");print $2}' filename)

awk -vrulename="$rulename" '
/source-address/{s=$1}
/destination-port/{d=$2}
/accept/{a=$2}
/reject/{r=$2}
{gsub(/;/, "");{printf "ip access-list extended" $rulename"\n\npermit ip" s,d,a}
' filename >> new.list

Anyone? I'm completely lost.

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
follow up...

Code:
awk -vrulename="$rulename" '
/source-address/{s=$1}
/destination-port/{d=$2}
/accept/{a=$2}
/reject/{r=$2}
{gsub(/;/, "");{printf "\nip access-list extended\n\n" $rulename"\n\npermit ip " $s,$d,$a"\n\n"}}
' filename|grep -v "term\|}\|{\|then" 
[code]

Gave me...

[code]ip access-list extended

            111.222.333.208/32

permit ip             111.222.333.208/32
ip access-list extended

But didn't include the rulename ....

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
awk variables don't need a $ in front of them unless you are referring to a field number.

For example, if t=3, then $t will refer to the contents of field 3, equivalent to $3.

So take away the $ in front of rulename and I think it would work (without examining it too closely...).

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top