2

how to remove the last string after "." character include the "." character itself

implementation can be with sed under Linux/Solaris operation system

example of IP address before change

      192.9.200.1     ( need to remove the .1 )

expected results

      192.9.200

other example

      100.2.2.101FFF

expected results

      100.2.2
1
  • just a side note, but using sed this way is advocating backtracking on the regex engine which is slow in case you need to change a huge amount of records on a regular basis.
    – Johannes
    May 8, 2013 at 14:23

2 Answers 2

6

maybe with cut instead of sed?

echo "10.10.10.5" | cut -d. -f-3

if it has to be sed

echo "10.10.10.5fsdfdsf" | sed -e 's/\.[^\.]*$//'
8

Why sed? How about manipulating with bash parameter expansion?

var="192.168.200.1"
echo ${var%.*}

192.168.200

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .