basically i have a csv i parse through. a user will supply me with a san switch he/she wants more info about... say the name is "pnj-sansw124"
now i can grep out every connection to that switch w/o issue because this sans switch pnj-sansw124 has multiple slots 1-10. and it looks like this in the csv "pnj-sansw124-1/23" where 1/23 is slot/port. so...
however i run into a problem where there is a san switch with no slots. so i would like to grep with a regex that would allow me to look for the "pnj-sansw124" but look for the "-[0-9]/" extension as well. so if its there, then continue to ask for slot. if not, go to a different section of code for this guy. a no slot san switch would look like "pnj-sansw110-58" where 58 is obviousy just the port.
i tried something like "pnj-sansw124-`([0-9]\{1\}|[0-9]\{2\})`//" but that didn't work out right.
Well, while testing this I think I'm running into a grep bug on HP-UX... it's working fine for me on Linux. What operating system are you using exactly?
However it does not work on HP-UX... as soon as you add the -w it fails to match, I can't for the life of me figure out why.
If you do choose to use egrep, or grep -E, it uses the Extended Regular Expression syntax, which has a subtle difference in the repetition syntax, no backslashes required before the squiggly brackets, e.g.:
this seems to work. however, obviously we start running into problems with higher numbers or more then two digit numbers. i don't feel like running all those ranges out. but for purposes for what i need it for now, its good. i'll fine tone it later with your suggestion.
now with grep -E, i fail. it didn't like that. egrep is good though.
thanks for the help. let me get to work and give it a go.
Well, I've tested it on my Solaris 10 box and grep appears to behave as expected there.
If you choose to use egrep, the only caveat is that the default /usr/bin/egrep doesn't support the {m,n} repetition syntax (why, oh why don't Sun ever update these utilities!?!) so you may prefer to use the less prehistoric version in /usr/xpg4/bin/egrep. Also, egrep does not support -w, so you need to surround your expression with \<...\> to match words.