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.
Asked
Active
Viewed 37 times
-3

Petr Mensik
- 26,874
- 17
- 90
- 115
-
Using [parameter expansion](https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion): `var=0.0.25; newvar=${var%.*}; echo "$newvar"`. – gniourf_gniourf Jun 28 '16 at 13:31
-
Did you try *anything*? – Thomas Ayoub Jun 28 '16 at 13:31
2 Answers
3
In bash you can do the following:
echo "${var%.*}"

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