The Wolfe Pack

Do I have experts among my followers: echo "123.4506000" | sed -E 's/(\.[0-9]*[1-9])?0+$//; s/\.$//' is intended to remove trailing 0s when its a number with a decimal point. But when there are no cifers behind the decimal point other than 0s, the whole number shall be stripped of the point and the 0s. What are I am doing wrong? Sharing appreciated.

@tschapajew Try this:

echo "123.4506000" | sed -E 's/\.?0+$//; s/(\.[0-9]*[1-9])0+$/\1/'

s/\.?0+$// removes .0000 with or without '.' at the end.

s/(\.[0-9]*[1-9])0+$/\1/
Strips trailing 0s only if there's at least 1 didget that isn't 0 before the 0s.

@fireborn Wow cool! Thanks. Works.

@fireborn Implemented. Mencioned you with thanks on my last commit: https://github.com/do9re/midi2hamlib

@tschapajew try this:

sed 's/\(\..*[^0]\)0*$/\1/; s/\.0*$//'
replies
0
announces
0
likes
0

@tschapajew @fireborn

Hmm. Das Problem ist gelöst. Aber warum mit regulären Ausdrücken? Die sind sehr mächtig und daher in der ausführung teuer. Das problem ließe sich mit wenig code in jeder prozeduralen sprache lösen, die einen string-datentyp hat. Das wäre billiger.

@Life_is @fireborn Oh. Du darfst gern auf's Repo schauen. Ich bin für jeden Verbesserungsvorschlag dankbar.

@tschapajew @fireborn

Geht leider nicht, mein mastodon client darf externe links nur öffnen, wenn im wifi, nicht mobil.

@Life_is @fireborn Der ist ja nichtso kompliziert, den kannstdu gut abtippen. Aber mach dir keinen Stress.