Hi All
I want to delete trailing zeros from varible.
ex:
if variable value is 1234.567000 result as 1234.567
if variable has 1234.0000 result as 1234
if variable as abcd.fgh result as abcd.fgh
Can somone give me a solution using awk?
Hi All
I want to delete trailing zeros from varible.
ex:
if variable value is 1234.567000 result as 1234.567
if variable has 1234.0000 result as 1234
if variable as abcd.fgh result as abcd.fgh
Can somone give me a solution using awk?
$ echo 1234.567000 | awk ' sub("\\.*0+$","") '
1234.567
$
$ echo 1234.000 | awk ' sub("\\.*0+$","") '
1234
Thx a lot is thr any way adding check that if it is a float den remove trailing zeros ?
i tried with above solution bt if variable has 1234 den it is returning null bt i want as 1234 it self
$ echo 1234 | awk ' { sub("\\.*0+$","");print} '
1234
Thx ...its working fine now ... bt i am unable to store the result in variable if i redirecting to file it is working fine ... y is it so??
Result= `echo $value | awk ' { sub("\\.*0+$","");print} '` # Not working
echo $value | awk ' { sub("\\.*0+$","");print} ' > File # working
it is failing for below value
echo 4000 | awk ' { sub("\\.*0+$","");print} '
getting result as 4
i want it as 4000 ... plz help me on this
Dont leave space before or after the equal sign.
Result=`echo $value | awk ' { sub("\\.*0+$","");print} '
If this is not the problem, then show the trace.
set -vx
Use this to get the trace
their was no space
trace is below
input=1234.56789000
+ input=1234.56789000
Result=`echo $input | awk ' sub("\\.*0+$","") '`
echo $input | awk ' sub("\.*0+$","") '
++ echo 1234.56789000
++ awk ' sub("\.*0+$","") '
+ Result=
echo $Result
+ echo
echo 4000 | awk ' { if($0 ~ /\./) sub("\\.*0+$","");print} '
Result=$(echo $input | awk ' { if($0 ~ /\./) sub("\\.*0+$","");print} ')
it is working perfectly now thx a lot onca again
Hi
I am not able to delete trailing zero's using awk.
2008-04-30|16|N|U|||||U|||+000000000000000000000000000.0000|+00000000000000000000.00000000000
2008-04-30||16|N|U|||||U|||+000000000000000000000000000.0000|+00000000000000000000.00000000000
cat e1.dat |awk -F "|" ' sub("\\.*0+$","") '
Thanks in advance
MR
awk -F'+' '{print $1 FS}' e1.dat
Output:
If the + sign is not needed remove the field separator FS.
Hi runin
If all zero's is ok .How about the below one if data is like this
e.dat
------
X0000202|PPP_XX|16|N|XXX|+00000000000124899.1200|+00000000000000169887.78302400000|-92251.0500
O/P Should be
X0000202|PPP_XX|16|N|XXX|124899.12|169887.783024|-92251.05
Thanks,
MR
Hi,
echo "X0000202|PPP_XX|16|N|XXX|+00000000000124899.1200|+00000000000000169887.78302400000|-92251.0500" | sed -e 's/|+00*/|/g' -e 's/0*|/|/g' -e 's/0*$//g'
Output:
X0000202|PPP_XX|16|N|XXX|124899.12|169887.783024|-92251.05
Thanks
Penchal
Hi Penchal,
Thanks a lot
Thanks
MR