how to introduce multiplication in shell scripting [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite













This question already has an answer here:



  • How to do integer & float calculations, in bash or other languages/frameworks?

    16 answers



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?







share|improve this question













marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 6 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 at 11:59










  • USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132
    – Arushix
    Jun 27 at 12:05










  • Which shell are you using?
    – andcoz
    Jun 27 at 12:31










  • its exponential of -3 output will be 0.00171
    – SivaPrasath
    Jun 27 at 12:50














up vote
1
down vote

favorite













This question already has an answer here:



  • How to do integer & float calculations, in bash or other languages/frameworks?

    16 answers



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?







share|improve this question













marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 6 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 at 11:59










  • USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132
    – Arushix
    Jun 27 at 12:05










  • Which shell are you using?
    – andcoz
    Jun 27 at 12:31










  • its exponential of -3 output will be 0.00171
    – SivaPrasath
    Jun 27 at 12:50












up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:



  • How to do integer & float calculations, in bash or other languages/frameworks?

    16 answers



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?







share|improve this question














This question already has an answer here:



  • How to do integer & float calculations, in bash or other languages/frameworks?

    16 answers



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?





This question already has an answer here:



  • How to do integer & float calculations, in bash or other languages/frameworks?

    16 answers









share|improve this question












share|improve this question




share|improve this question








edited Jul 9 at 12:32









schily

8,57421435




8,57421435









asked Jun 27 at 11:56









Nayak

306




306




marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 6 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.






marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 6 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 at 11:59










  • USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132
    – Arushix
    Jun 27 at 12:05










  • Which shell are you using?
    – andcoz
    Jun 27 at 12:31










  • its exponential of -3 output will be 0.00171
    – SivaPrasath
    Jun 27 at 12:50












  • 1




    post a testable input fragment
    – RomanPerekhrest
    Jun 27 at 11:59










  • USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132
    – Arushix
    Jun 27 at 12:05










  • Which shell are you using?
    – andcoz
    Jun 27 at 12:31










  • its exponential of -3 output will be 0.00171
    – SivaPrasath
    Jun 27 at 12:50







1




1




post a testable input fragment
– RomanPerekhrest
Jun 27 at 11:59




post a testable input fragment
– RomanPerekhrest
Jun 27 at 11:59












USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132
– Arushix
Jun 27 at 12:05




USe tac some_directory/*.pre | grep -im1 "vdr" | cut -c129-132
– Arushix
Jun 27 at 12:05












Which shell are you using?
– andcoz
Jun 27 at 12:31




Which shell are you using?
– andcoz
Jun 27 at 12:31












its exponential of -3 output will be 0.00171
– SivaPrasath
Jun 27 at 12:50




its exponential of -3 output will be 0.00171
– SivaPrasath
Jun 27 at 12:50










1 Answer
1






active

oldest

votes

















up vote
10
down vote



accepted










Using awk:



As per your expected output:



echo 1.710577E-03 | awk 'printf "%.2fn",a=$1*1000; a'
1.71


Actual roundoff:



echo 1.710577E-03 | awk 'printf "%.5fn",$1'
0.00171


  • %.5 print up to 5 decimals.


  • f float converter.






share|improve this answer























  • Thanks.....will you please explain the second block after pipe.!!
    – Nayak
    Jul 6 at 5:28











  • is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
    – Nayak
    Jul 9 at 9:30











  • I have already tried...but unfortuntely in combination with plugin does not work.
    – Nayak
    Jul 9 at 9:50










  • can you share part of a plugin with error?
    – SivaPrasath
    Jul 9 at 9:52










  • awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
    – Nayak
    Jul 9 at 12:13

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
10
down vote



accepted










Using awk:



As per your expected output:



echo 1.710577E-03 | awk 'printf "%.2fn",a=$1*1000; a'
1.71


Actual roundoff:



echo 1.710577E-03 | awk 'printf "%.5fn",$1'
0.00171


  • %.5 print up to 5 decimals.


  • f float converter.






share|improve this answer























  • Thanks.....will you please explain the second block after pipe.!!
    – Nayak
    Jul 6 at 5:28











  • is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
    – Nayak
    Jul 9 at 9:30











  • I have already tried...but unfortuntely in combination with plugin does not work.
    – Nayak
    Jul 9 at 9:50










  • can you share part of a plugin with error?
    – SivaPrasath
    Jul 9 at 9:52










  • awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
    – Nayak
    Jul 9 at 12:13














up vote
10
down vote



accepted










Using awk:



As per your expected output:



echo 1.710577E-03 | awk 'printf "%.2fn",a=$1*1000; a'
1.71


Actual roundoff:



echo 1.710577E-03 | awk 'printf "%.5fn",$1'
0.00171


  • %.5 print up to 5 decimals.


  • f float converter.






share|improve this answer























  • Thanks.....will you please explain the second block after pipe.!!
    – Nayak
    Jul 6 at 5:28











  • is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
    – Nayak
    Jul 9 at 9:30











  • I have already tried...but unfortuntely in combination with plugin does not work.
    – Nayak
    Jul 9 at 9:50










  • can you share part of a plugin with error?
    – SivaPrasath
    Jul 9 at 9:52










  • awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
    – Nayak
    Jul 9 at 12:13












up vote
10
down vote



accepted







up vote
10
down vote



accepted






Using awk:



As per your expected output:



echo 1.710577E-03 | awk 'printf "%.2fn",a=$1*1000; a'
1.71


Actual roundoff:



echo 1.710577E-03 | awk 'printf "%.5fn",$1'
0.00171


  • %.5 print up to 5 decimals.


  • f float converter.






share|improve this answer















Using awk:



As per your expected output:



echo 1.710577E-03 | awk 'printf "%.2fn",a=$1*1000; a'
1.71


Actual roundoff:



echo 1.710577E-03 | awk 'printf "%.5fn",$1'
0.00171


  • %.5 print up to 5 decimals.


  • f float converter.







share|improve this answer















share|improve this answer



share|improve this answer








edited Jul 9 at 9:34


























answered Jun 27 at 12:54









SivaPrasath

3,88611737




3,88611737











  • Thanks.....will you please explain the second block after pipe.!!
    – Nayak
    Jul 6 at 5:28











  • is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
    – Nayak
    Jul 9 at 9:30











  • I have already tried...but unfortuntely in combination with plugin does not work.
    – Nayak
    Jul 9 at 9:50










  • can you share part of a plugin with error?
    – SivaPrasath
    Jul 9 at 9:52










  • awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
    – Nayak
    Jul 9 at 12:13
















  • Thanks.....will you please explain the second block after pipe.!!
    – Nayak
    Jul 6 at 5:28











  • is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
    – Nayak
    Jul 9 at 9:30











  • I have already tried...but unfortuntely in combination with plugin does not work.
    – Nayak
    Jul 9 at 9:50










  • can you share part of a plugin with error?
    – SivaPrasath
    Jul 9 at 9:52










  • awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
    – Nayak
    Jul 9 at 12:13















Thanks.....will you please explain the second block after pipe.!!
– Nayak
Jul 6 at 5:28





Thanks.....will you please explain the second block after pipe.!!
– Nayak
Jul 6 at 5:28













is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
– Nayak
Jul 9 at 9:30





is it possible to avoid 'a' variable in 'awk' block ? I am trying to couple this command with another programm and 'a' is a kind of conficting. the entire command is : rea plu echo set var num 0:ex1 tac *.pre | grep -i -m1 "vdr" | cut -c129-140 | echo awk 'printf "%.2fn",a=$1*1000; a'``.... 'rea plu echo set var num 0:ex1' is plugin from another programm, and rest is shell.
– Nayak
Jul 9 at 9:30













I have already tried...but unfortuntely in combination with plugin does not work.
– Nayak
Jul 9 at 9:50




I have already tried...but unfortuntely in combination with plugin does not work.
– Nayak
Jul 9 at 9:50












can you share part of a plugin with error?
– SivaPrasath
Jul 9 at 9:52




can you share part of a plugin with error?
– SivaPrasath
Jul 9 at 9:52












awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
– Nayak
Jul 9 at 12:13




awk: cmd. line:1: {printf ...then in next line awk: cmd. line:1: ^ unexpected newline or end of string
– Nayak
Jul 9 at 12:13


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?