sed trim last 2 octets of ip address

July 23, 2011 at 19:58:44
Specs: ubuntu 11.04
I am trying to take a standard ip address, 192.168.1.2 and trim it to 192.168.

I have tried using sed, but can only get the last octet trimmed. any help?


See More: sed trim last 2 octets of ip address

Report •

#1
July 24, 2011 at 08:13:16
This works for all versions of sed:

echo "192.168.1.2" |sed 's/\.*.$//'|sed 's/\.*.$//'

This works for GNU (i.e. Linux) sed:

echo "192.168.1.2" |sed 's/\(\.*.\)\{2\}$//'


Report •
Related Solutions


Ask Question