Reformatted slightly for email.  Obviously you can play with the
output formatting to your heart's content...

[EMAIL PROTECTED] wrote:
> 
> routers: [
> 
>         router1 [  domain {        }
>                    filepath {       }
>                    confpath {       }
>                    interfaces [
>                                 ["serial1" "up" 1 {description}]
>                                 ["ethernet1" "down" 2 {description}]
>                               ]
>                 ]
> 
>         router2 [  domain {     }
>                    filepath {   }
>                    confpath {   }
>                    interfaces [
>                                 ["ethernet1" "up" 1 {description}]
>                                 ["hssi1" "down" 2 {description}]
>                               ]
>                 ]
>           ]
> 
> How can I build a foreach loop around this to print each router name and
> its interfaces. Also, could I incorporate a find statement to show each
> router and is "up" interfaces...?
> 

    foreach [id descr] routers [
        print id
        foreach itf descr/interfaces [print mold itf]
    ]

produces

    router1
    ["serial1" "up" 1 "description"]
    ["ethernet1" "down" 2 "description"]
    router2
    ["ethernet1" "up" 1 "description"]
    ["hssi1" "down" 2 "description"]

and

    foreach [id descr] routers [
        print id
        foreach itf descr/interfaces [
            if itf/2 = "up" [print mold itf]
        ]
    ]

gets you

    router1
    ["serial1" "up" 1 "description"]
    router2
    ["ethernet1" "up" 1 "description"]

-jn-

Reply via email to