1

This question already has an answer here:

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?

marked as duplicate by Kusalananda shell-script Jul 6 '18 at 5:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    post a testable input fragment – RomanPerekhrest Jun 27 '18 at 11:59
  • USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132 – Arushix Jun 27 '18 at 12:05
  • Which shell are you using? – andcoz Jun 27 '18 at 12:31
  • its exponential of -3 output will be 0.00171 – msp9011 Jun 27 '18 at 12:50
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.