Script to parse an access-list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to parse an access-list
# 1  
Old 07-10-2008
Script to parse an access-list

Folks,

I have a textfile with the config of my router. Part of that config looks like this:

router config
...
ip access-list extended MyAccessList
remark this is my security rule
permit host 10.0.0.1 any
deny host 10.0.0.2 any
...
ip access-list extended YourAccessList
remark this is your security rule
permit host 192.168.0.1 any
deny host 192.168.0.2 any
...
router config
...

I want to script something that shows MyAccessList and all related entries (starting with remark/permit/deny).

So this should be the output:

ip access-list extended MyAccessList
remark this is my security rule
permit host 10.0.0.1 any
deny host 10.0.0.2 any
...

I have been thinking about combining grep and awk and a couple of other paths, but I don't even get close Smilie

Anyone an idea how to start something like this?

Much appreciated,

Philipz
# 2  
Old 07-10-2008
You can simply do something like:

Code:
awk '/MyAccessList$/{
  print;getline
  print;getline
  print;getline
  print;exit
}' file

Regards
# 3  
Old 07-10-2008
Another one and shorter:

Code:
awk '/MyAccessList$/{f=4}f{print;f--}' file

Regards
# 4  
Old 07-10-2008
You can also use sed this way so that if the number of lines following the line containing MyAccessList is unknown, they will all get printed until you hit the line containing YourAccessList:

sed -n '/MyAccessList/,/YourAccessList/{/YourAccessList/d;p;}' file

Hope this helps.
# 5  
Old 07-10-2008
Quote:
Originally Posted by Franklin52
Another one and shorter:

Code:
awk '/MyAccessList$/{f=4}f{print;f--}' file

Regards
... a bit shorter:
Code:
awk '/^ip access-list extended/ {f=4}f--' myFile

# 6  
Old 07-10-2008
Quote:
Originally Posted by vgersh99
... a bit shorter:
Code:
awk '/^ip access-list extended/ {f=4}f--' myFile

vgersh99,

This prints unwanted lines if f becomes negative.

Regards
# 7  
Old 07-10-2008
Quote:
Originally Posted by vgersh99
... a bit shorter:
Code:
awk '/^ip access-list extended/ {f=4}f--' myFile

.. too short Smilie
Let's sed
Code:
sed -n 'N;N;N;/My/p' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed/awk script to parse list of bandwidth rules

Hello all gurus, I have a long list of rules as below: 20 name:abc addr:203.45.247.247/255.255.255.255 WDW-THRESH:12 BW-OUT:10000000bps BW-IN:15000000bps STATSDEVICE:test247 STATS:Enabled (4447794/0) <IN OUT> 25 name:xyz160 addr:203.45.233.160/255.255.255.224 STATSDEVICE:test160... (3 Replies)
Discussion started by: sb245
3 Replies

2. Shell Programming and Scripting

Help parse comma separated list

I have a list of files with the same name, but they have a different date stamp in the name. I can find the first file, but I need to find the second file. I am using this information to create a variable I use later. Here is a example of how I find the first file. "ls -mr... (11 Replies)
Discussion started by: NoMadBanker
11 Replies

3. Homework & Coursework Questions

Parse a Web Server Access Log

1. The problem statement, all variables and given/known data: Write a parser for a web server access log that will provide the statistics outlined below. Remember to format your output in a neat form. You may complete this assignment with one Awk script or a shell script using a combination of... (6 Replies)
Discussion started by: codyhazelwood
6 Replies

4. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies

5. Solaris

List users who have administrative access

Hi , Could you please give me the commands for the following. 1.list users who have direct access to solaris database at os-level 2.list users who have administrative access at os-level in solaris Please also let me know how to figure out these specific users i need from a... (6 Replies)
Discussion started by: James777
6 Replies

6. Shell Programming and Scripting

How to parse a list of data to find the missin stats.

HI ALL, Thanks for helping me with my last post. :b: I have one more doubt, i want to parse a set of data. which is consisting of some values that occured in particular period of time. And when i parse down if there is a missing time period then it should show the two rows between which the... (3 Replies)
Discussion started by: asirohi
3 Replies

7. UNIX for Dummies Questions & Answers

How can I get the list of files if I have root access?

Hi, I'm very new and dumb in linux. What I do is: I use putty to connect to the linux server. I use auth.komtels.ru as a connection line root and oP04Koh0 as a password port 6262, and SSH protocol now I need to get the list of the files, how could I do it? (1 Reply)
Discussion started by: linuxbeginner
1 Replies

8. Solaris

Command for access control list

Hi, I want to set access control list on folders but it should be recursively, any Idea? command (1 Reply)
Discussion started by: manoj.solaris
1 Replies

9. Shell Programming and Scripting

Access Control List

Hey all, I have a directory (own by user: b; group: grpB) which I want a user (user: a; group: grpA) to be able to read and execute from, I wonder if I should add user a to this particular directory's ACL or that I would add group grpB to user a's subgroup? I would like to know the difference... (3 Replies)
Discussion started by: mpang_
3 Replies

10. UNIX for Dummies Questions & Answers

list of books I have access to

I have another question. I have access to the books listed below, however I know that not all of them are the lates and greatest and some are over 10 years old. So the question is are most of these books still a good idea to read. Or should I try and pick up the latest and greatest editions? ... (5 Replies)
Discussion started by: bru
5 Replies
Login or Register to Ask a Question