Reply to topic  [ 2 posts ] 
Regex/egrep help 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
Hi all,

I've got this piece of shell script:
Code:
# Set up array for all IP addresses
IPADDRS=""
COUNTER=0

for EACH in `ifconfig -a`; do
   # Look for four sets of grouped numbers separated by periods.
   # Groups are between 1 and 3 digets in size and consist of numbers only.
   IPADDRS[$COUNTER]=`echo $EACH | egrep [0-9]\{1,3\}"\."[0-9]\{1,3\}"\."[0-9]\{1,3\}"\."[0-9]\{1,3\}`
   
   # Increment counter
   COUNTER=$(( $COUNTER + 1 ))
done


It should look through the output of `ifconfig -a` and place IP addresses into the IPADDRS array. It did work...But now it doesn't, but I'm not sure why...
Even if I strip out the array stuff, it's not echo'ing the IP addresses...

I'm using OpenSolaris 2009.06 for this particular project. The same expression works on my Mac though...

Any ideas?
Thanks,
Ben


Mon Mar 01, 2010 5:35 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
Seems to work now :)

Code:
# Set up array for all IP addresses
IPADDRS=""
COUNTER=0

for EACH in `ifconfig -a`; do
   # Look for four sets of grouped numbers separated by periods.
   # Groups are between 1 and 3 digets in size and consist of numbers only.
   # I.E. A standard IP address
   IPADDRS[$COUNTER]=`echo $EACH | egrep [0-9]\{1,3\}"\."[0-9]\{1,3\}"\."[0-9]\{1,3\}"\."[0-9]\{1,3\}`
   
   # If something was found, increment counter
   if [[ ${IPADDRS[$COUNTER]} ]]; then
      COUNTER=$(( $COUNTER + 1 ))
   fi
done


Mon Mar 01, 2010 7:07 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.