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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Best way to evaluate file.

Status
Not open for further replies.

NetworkGhost

IS-IT--Management
Apr 12, 2005
1,324
US
I want to write a script that will grep a file for a certain keyword. Once the keyword is found I want it to evaluate the lines below for anoth value until it cant find it then start over with w new value for the file. Any scripting guys out there have a suggestion for a scripting language that can do this?
 
thanks olded, That looks like a start. I have never used awk before but will give it a crap shoot.

Basically Im trying to grep through a router config and take all the ACLs, networkobjects and place them in a sep. file. Not to hard but for the network object part I the object list would go as follows


object-group network test-group
network-object host 10.10.10.10
network-object 192.168.1.0 255.255.255.0
network-object 192.168.50.0 255.255.255.0
network-object 192.168.60.0 255.255.255.0
access-list acl_inside permit ip any any
access-list acl_inside permit ip any host 64.0.0.6
access-list acl_inside permit ip any host 64.0.0.7



So basically what I want is to grep for the string "object-group". If the the grep returns a value then continue to grep directly after that line for "network-object" and output those values until the next line does not match.

Im going to try to use AWK, If not that then Perl. I like that perl can be run on windows and unix.
 
if you have empty lines between the config items, you could
do a paragraph grep like so:

grep -p object-group|egrep 'object-group|network-object'

Even if there aren't empty lines (default paragraph separator) beween the config items, then you could try and find a way to force empty lines by sed-ing the data first and e.g. inserting an empty line before the string "object-group" (google for sed oneliners to find out how to accomplish that)


HTH,

p5wizard
 
Yeah, my goal is to turn this into a html doc that can be used to veiw just acl's and the appropriate object-groups.
 
you can do it with awk which works with most UNIX flavors

something similar to the below

awk '#
BEGIN { find1=0; find2=0; }
/find first/ {find1 = 1;}
/find second/ {find2 = 1;}
{
if ( find1 == 1 ) { find2=0; }
if ( find1 == 1 && find2 == 1 ) { print $0; }
}
#' > outputfile.txt

replace the
find first with first text pattern to search
find second with second text pattern to search

replace the print $0 with what you want to do when you find both patterns (in my example print $0 just prints the line with the second pattern)
 
Hi

Excuse me, but when will the second [tt]if[/tt]'s condition evaluate to true ?
Code:
   if ( find1 == 1 ) { find2=0; }
   if ( find1 == 1 && find2 == 1 ) { print $0; }

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top