Apr 24, 2015 #1 yesornot Technical User Apr 15, 2015 7 PL $ echo 4000.24320000000000223230000|sed s/0*$//g 4000.2432000000000022323 (ok) $ echo 4000.0000|sed s/0*$//g 4000. (not ok - expected 4000) $ echo 4000|sed s/0*$//g 4 (not ok - expected 4000)
$ echo 4000.24320000000000223230000|sed s/0*$//g 4000.2432000000000022323 (ok) $ echo 4000.0000|sed s/0*$//g 4000. (not ok - expected 4000) $ echo 4000|sed s/0*$//g 4 (not ok - expected 4000)
Apr 24, 2015 Thread starter #2 yesornot Technical User Apr 15, 2015 7 PL ok, this worked awk '{if($0~/\./){sub("0*$","",$0);sub("\\.$","",$0);}print}' Upvote 0 Downvote
Apr 26, 2015 #3 Annihilannic MIS Jun 22, 2000 6,317 AU This works. Unfortunately complex because sed -r doesn't seem to support greediness (?) in ERE: Code: sed -r 's/(\.([0-9]*[1-9])?)0+$/\1/;s/\.$//' By contrast, perl does: Code: perl -pe 's/(\.[0-9]*?)0+$/\1/;s/\.$//' But the awk solution is probably the must human-compatible anyway. Annihilannic [small]tgmlify - code syntax highlighting for your tek-tips posts[/small] Upvote 0 Downvote
This works. Unfortunately complex because sed -r doesn't seem to support greediness (?) in ERE: Code: sed -r 's/(\.([0-9]*[1-9])?)0+$/\1/;s/\.$//' By contrast, perl does: Code: perl -pe 's/(\.[0-9]*?)0+$/\1/;s/\.$//' But the awk solution is probably the must human-compatible anyway. Annihilannic [small]tgmlify - code syntax highlighting for your tek-tips posts[/small]