0

With awk I filtered a file and saved into a variable foo. For example, echo $foo returns 1700 / 2340.

edit: I know how to filter again and save each number into a variable so some math could be done with the 2 variables.

But I'd like to know if it is possible to evaluate the expression easily, I mean, some command to produce 0,726495726 (the result of the division 1700 / 2340), e.g., command $foo outputs 0,726495726.

Sigur
  • 355
  • 8
  • 19
  • `echo "scale=2; $foo" | bc -l` will do it. – codeforester Sep 30 '17 at 23:58
  • @bfontaine, I don't think it is duplicated, because I would like to avoid using two variables. I know how to divide. I'd like to *recognize that the string is a division of two numbers and return the evaluated value*. – Sigur Oct 01 '17 at 00:03
  • @codeforester, exactly. Thanks so much. If you wish, please, post as answer. – Sigur Oct 01 '17 at 00:05
  • Guys, I'm checking the possible answers cited as duplicated but I think it is different approach. I don't have 2 variables. I have a single one with such expression `3 / 4`. I didn't find the answer given by @codeforester on those posts. – Sigur Oct 01 '17 at 00:30
  • In bash it would be a dangerous thing to evaluate, as it could contain commands, but ˋeval “r=\$\[$foo\]“ should do. – eckes Oct 01 '17 at 00:33

0 Answers0