After a program is finished, I obtain an output file(FILE
) containing two consecutive lines including the word "number".
...some texts...
number1 3.145
number2 1.56
...some texts...
Only the two lines in FILE
contain "number". The values vary depending on the input file for the calculation. Sometimes the program prints values in scientific notation like 6.145E-03
.
What I would like to do is extract the two values from the two lines and do some arithmetic operations using bash commands. For example, say the two values are $num1
and $num2
, 10*($num1 + $num2)/($num1 - $num2)
.
I think awk
has an answer to this question.
p.s.
If not considering scientific notation leads a much simpler answer, I would try that solution. Scientific notation appears only some special cases which can be neglected.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…