$ cat usagealarm.txt
Element1|23.4567|11:32PM|OK
Element2|45.2134|10:33PM|OK
Element3|21.5217|11:52PM|OK
Element4|29.4367|11:18PM|OK
Element5|27.4577|12:72PM|OK
The 2nd values, we need to round to 2 digits right of decial point.
i.e.
required output:
Element1|23.46|11:32PM|OK
Element2|45.21|10:33PM|OK
Element3|21.52|11:52PM|OK
Element4|29.44|11:18PM|OK
Element5|27.46|12:72PM|OK
$ awk 'BEGIN{OFS=FS="|"} { $2=sprintf("%.2f",$2)}1' usagealarm.txt
or
$ awk 'BEGIN{OFS=FS="|"} { $2=sprintf("%.2f",$2)} {print}' usagealarm.txt
Saturday, April 12, 2008
Round float values using sprintf - AWK
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment