-3

Say I have a string 0.0.25, how do I delete the last part after dot (including it) to make it like 0.0? Note that last part can have variable number of digits.

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115

2 Answers2

3

In bash you can do the following:

 echo "${var%.*}"

See the Shell Parameter Expansion section of the manual.

gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43
  • @hek2mgl: I don't think so. The downvote means _This answer is not useful._ And it's not the case! what I do in this case is stay neutral… – gniourf_gniourf Jun 28 '16 at 13:37
  • 1
    @gniourf_gniourf I've already reverted it. The basic problem here is that even after the question is closed as a duplicate there is still a grace period to post answers - which is, following meta, by design. imo it renders the close vote useless since experience shows that, especially for simple, duplicate problems answers will arrive pretty quickly, within that grace period – hek2mgl Jun 28 '16 at 13:52
0

Using awk you could:

echo "0.0.25" | awk -F. '{print $1"."$2}'
JNevill
  • 46,980
  • 4
  • 38
  • 63