如何使用 awk/sed 更改小数点分隔符? [英] How to change the decimal separator with awk/sed?
本文介绍了如何使用 awk/sed 更改小数点分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 sed
或 awk<将数字格式(不同的小数分隔符)从
XXXXXX.XXX
更改为 XXXXXX,XXX
/代码>?
How to change number format (different decimal separator) from XXXXXX.XXX
to XXXXXX,XXX
using sed
or awk
?
推荐答案
你想要多严格?您可以更改所有 .
字符,正如其他人所建议的那样,但是如果您有更多的数字,这将允许很多误报.更严格的是要求点的两边都有数字:
How rigorous do you want to be? You could change all .
characters, as others have suggested, but that will allow a lot of false positives if you have more than just numbers. A bit stricter would be to require that there are digits on both sides of the point:
$ echo 123.324 2314.234 adfdasf.324 1234123.daf 255.255.255.0 adsf.asdf a1.1a |
> sed 's/([[:digit:]]).([[:digit:]])/1,2/g'
123,324 2314,234 adfdasf.324 1234123.daf 255,255,255,0 adsf.asdf a1,1a
这确实允许在一些奇怪的情况下进行更改,即 255.255.255.0
和 a1.1a
,但可以干净地处理正常"数字.
That does allow changes in a couple of odd cases, namely 255.255.255.0
and a1.1a
, but handles "normal" numbers cleanly.
这篇关于如何使用 awk/sed 更改小数点分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文