matasimi
asked on
Extract numerical values from text file in bash script
Hi
How can I put a numerical value to bash script variable from text file?
I have a text file with entire numerical values in some strings:
$cat numbers.txt:
23424
534
234566
95
I need select an first line put to text varible, convert to numerical value and then make arithmetical operation (add and divide) with these values.
Thank you.
How can I put a numerical value to bash script variable from text file?
I have a text file with entire numerical values in some strings:
$cat numbers.txt:
23424
534
234566
95
I need select an first line put to text varible, convert to numerical value and then make arithmetical operation (add and divide) with these values.
Thank you.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hello
With ghostdog74 solution I get character values from text file and with omarfarid solution I can arithmetical operation in the form that I want.
Thank you
With ghostdog74 solution I get character values from text file and with omarfarid solution I can arithmetical operation in the form that I want.
Thank you
No need to use expr in a bash/ksh/zsh script as they have inbuilt maths functions, eg:
a=1
let b=a+10
ASKER