cat file contains inet addr:192.168.154.102 Bcast:192.168.154.255 Mask:255.255.255.0 inet addr:127.0.0.1 Mask:255.0.0.0i am extracting the ipaddress(192.168.154.102 and 127.0.0.1) using sed like this :sed -ne 's/.*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/p'but it just gives :5.255.255.05.0.0.0
Sed not giving the first occurence of pattern
sed
Use awk:$ echo inet addr:192.168.154.102 Bcast:192.168.154.255 Mask:255.255.255.0 | awk '{ split($2, a, :); print a[2] }'192.168.154.102If you absolutely must use sed, e.g.:echo inet addr:192.168.154.102 Bcast:192.168.154.255 Mask:255.255.255.0 | sed 's#.*addr:\([0-9.]*\).*#\1#g'192.168.154.102