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     ( need to remove the .1 )

expected results


other example

expected results

  • 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 '13 at 14:23

maybe with cut instead of sed?

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

if it has to be sed

echo "" | sed -e 's/\.[^\.]*$//'
| improve this answer | |

Why sed? How about manipulating with bash parameter expansion?

echo ${var%.*}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.