Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: search for a string and return previous relating string if found

by NetWallah (Canon)
on Dec 06, 2017 at 19:54 UTC ( [id://1205044]=note: print w/replies, xml ) Need Help??


in reply to search for a string and return previous relating string if found

Try this:
perl -nE "m/^interface (\S+)/ and $int=$1; m/ spanning-tree guard root +/ and print qq|$int $_|" YOUR-FILE.txt
prints:
FastEthernet1/0/3 spanning-tree guard root
Somewhat simple-minded, but should do the trick.

                All power corrupts, but we need electricity.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found