1

My command is:

tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-140  

Output is:

1.710577E-03  

I want the output to be:

1.71

How can I achieve this in the shell command?

schily
  • 19,173
Nayak
  • 65

1 Answers1

4

Using awk:

As per your expected output:

echo 1.710577E-03 | awk '{printf "%.2f\n",a=$1*1000; a}'
1.71

Actual roundoff:

echo 1.710577E-03 | awk '{printf "%.5f\n",$1}'
0.00171
  • %.5 print up to 5 decimals.

  • f float converter.

Siva
  • 9,077