r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Janko
14-May-2009
[2189x2]
sometimes an easier solution is possible if you do it in more parse 
runs
or if only comma is the problem slap it at the end and be done with 
it
Henrik
14-May-2009
[2191]
yes, for something like that, I would do some simple splitting to 
get the numbers isolated.
Janko
14-May-2009
[2192]
... from where do you parse 5 out... is that supose NUM-NUM suppose 
to be ranges?
mhinson
14-May-2009
[2193]
so I will add a comma to the end, then parse data [any [ some digit 
#"/" copy result #"," (insert results result) | skip]]
Janko
14-May-2009
[2194]
If it is I wouldn't call that a parse problem, ... remember you have 
to divide and conquer the problems , and that looks like a compound 
problem which parsing is not the big part of.. you just need regular 
"split" method
mhinson
14-May-2009
[2195]
some are ranges & some are single ports
Janko
14-May-2009
[2196]
what does 2 mean in 2/x-y ?
mhinson
14-May-2009
[2197]
the 2 is a module number on a Cisco catos switch
Janko
14-May-2009
[2198]
I qould 1) split on comma to get list of entities  2) for each entity 
if it's a single num append it to block, else split again and append 
 whole range to the block
mhinson
14-May-2009
[2199]
the port information is stored in a form like
set port disable 2/2,2/4,2/6-8
set port disable 3/1-5,3/7
Then the same sort of thing for the names given to the ports.

I want to extract it all into a standard format for analysis & comparison 
of IOS based information (done the IOS stuff ok)
BrianH
14-May-2009
[2200]
a: [...]
some-a-with-comma: [a any ["," a]]
mhinson
14-May-2009
[2201]
CIsco operating systems are IOS or CATOS on switches and output formats 
are very different.
Ladislav
14-May-2009
[2202]
mhinson: the above {copy result #","} does not look intended to me
mhinson
14-May-2009
[2203]
ah, do I need a copy result to perhaps?
Ladislav
14-May-2009
[2204x3]
if {copy result to ...} is what you want then I understand why you 
are having trouble with the END
not-comma: complement charset ","
copy result any [not-comma | skip]
sorry, just copy result not-comma
PeterWood
14-May-2009
[2207]
I think the advice to break the problem down and use more than one 
parse statement is good advice. Let's see how we can do that.


I'll go through how I would approach the problem step by step. Sorry 
that I'll be squashing things on to one line but AltME paste doesn't 
work well on Mac.
mhinson
14-May-2009
[2208]
:-)
PeterWood
14-May-2009
[2209]
I usually try to take a few small steps rather than try to get the 
answer straight away.

The test data:

>> inp:  {random 2/2,2/4-6,2/33-37}

== "random 2/2,2/4-6,2/33-37"
mhinson
14-May-2009
[2210]
random is sometimes a word & sometimes a number between 1 & 1000
PeterWood
14-May-2009
[2211x2]
We'll need to look for digits so :

> digit: charset [#"0" - #"9"]                   
  
== make bitset! #{

000000000000FF03000000000000000000000000000000000000000000000000

}
Does random ever have the sequence 2/number in it?
mhinson
14-May-2009
[2213x2]
no
specific words (not many of them) on numeric alone
PeterWood
14-May-2009
[2215]
So what we need to look for are the patterns 2/number and 2/number-number.
mhinson
14-May-2009
[2216x3]
on=or
or 3/number...etc or 4/ or 12/
but not on the same occasion
PeterWood
14-May-2009
[2219x2]
Let's start with 2/ and see how we get on 


>> parse/all inp [ any [copy range "2/" some digit  (print range) 
| skip ]]
2/

2/

2/
So I've found all the sequences of 2/ but didn't capture the following 
digits.

Can you see my mistake?
mhinson
14-May-2009
[2221]
I see why it has done that but I dont know how to extend the copy 
to the comma except with 
to #","
PeterWood
14-May-2009
[2222x2]
Let's change the parse rule so that I capture more than just the 
2/:


>> parse/all inp [ any [copy range ["2/" some digit]  (print range) 
| skip ]]
2/2
2/4
2/33

== true
You don't need to worry about the commas. skip will take care of 
them.
mhinson
14-May-2009
[2224]
so copy range has captured everything up to the point it no longer 
matches the expression in the []  a bit like a regular expression 
match.
PeterWood
14-May-2009
[2225x2]
So now I'm capturing the first number after the 2/ but not the range. 
So let's add a little more to the parse rule to capture that:


>> parse/all inp [ any [copy range ["2/" some [digit | "-"]]  (print 
range) | skip ]]                                                 
                         
2/2
2/4-6
2/33-37

== true
Yes copy captures everything that it matches.
mhinson
14-May-2009
[2227]
a bit like copy thru?
PeterWood
14-May-2009
[2228x2]
You only need to use thru when you can't specify exactly what you 
want to copy.
I think of it this way:

copy variable pattern-to-copy 


copy variable pattern-to-start-copying-from thru pattern-to-stop-copying-at
mhinson
14-May-2009
[2230]
So essential in cases where the middle bit is truly unpredictable
PeterWood
14-May-2009
[2231x2]
Yes
Now we can change the parse rule to work with 3/. 4 and  /12:


> parse/all inp [ any [copy range [["2/" | "3/" | "4/" | "12/"]  
some digit]  (print range) | skip ]]                             
              
2/2
2/4
2/33
== true
mhinson
14-May-2009
[2233]
the 2/ part can be any number from 1 to 13
PeterWood
14-May-2009
[2234]
Do you want to capture all of them?
mhinson
14-May-2009
[2235]
absolutely
Ladislav
14-May-2009
[2236]
one-to-thirteen: ["1" digit | non-zero-digit]
PeterWood
14-May-2009
[2237]
Then we can come up with a pattern for them:

digit opt digit "/"
mhinson
14-May-2009
[2238]
could we use 1 2 digit #"/"   ?