Link to home
Start Free TrialLog in
Avatar of matasimi
matasimiFlag for Argentina

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.
ASKER CERTIFIED SOLUTION
Avatar of ghostdog74
ghostdog74

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matasimi

ASKER

Thank you for fast and exact solution.
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
Avatar of Tintin
Tintin

No need to use expr in a bash/ksh/zsh script as they have inbuilt maths functions, eg:

a=1
let b=a+10

Open in new window