x404.co.uk
http://www.x404.co.uk/forum/

Regex/egrep help
http://www.x404.co.uk/forum/viewtopic.php?f=4&t=6626
Page 1 of 1

Author:  forquare1 [ Mon Mar 01, 2010 5:35 pm ]
Post subject:  Regex/egrep help

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

Author:  forquare1 [ Mon Mar 01, 2010 7:07 pm ]
Post subject:  Re: Regex/egrep help

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/