0

I want to store this value 3.4.1 as 3004001 so 3*1,000,000 + 4*1,000 + 1

I want to do this is a bash script how can I do that?

jww
  • 97,681
  • 90
  • 411
  • 885
  • 4
    show your efforts – RomanPerekhrest Jul 14 '17 at 14:21
  • `sed 's/\./00/g'` – William Pursell Jul 14 '17 at 14:30
  • [Bash multiplication and addition](https://unix.stackexchange.com/q/299321/56041) on [Unix & Linux Stack Exchange](http://unix.stackexchange.com/), [Multiplication on command line terminal](https://stackoverflow.com/q/11039876/608639), [Variables Multiplication](https://stackoverflow.com/q/15213127/608639), etc. – jww Jul 14 '17 at 14:47

1 Answers1

1
val="3.4.1"
awk -F. '{ print ($1*1000000)+($2*1000+1) }' <<< $val

Use awk to split the data with field delimiter . and then perform the necessary math printing the result.

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18