1

if assume that the output of the command is this:

7485.5

how do i separate the digit using grep into this:

7
4
8
5

and this output I able to manipulate it and assigned to new variable:

$num1=7
$num2=4
$num3=8
$num4=5
tembikai
  • 11
  • 1
  • 1
    Why `grep`? It seems the completely wrong tool here. – kabanus Mar 28 '19 at 07:15
  • you can use [bash parameter expansion](https://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion) to get individual characters from string - that might suit better than using tools like grep/cut/awk here – Sundeep Mar 28 '19 at 07:19
  • for example, if `7485.5` is saved in a variable `num` then `${num:2:1}` will give `8` – Sundeep Mar 28 '19 at 07:20
  • Do you really want multiple variables? I mean, how would you address them if you the length of the number varies? An array seems more appropriate. – Socowi Mar 28 '19 at 08:15
  • 1
    thanks for the suggestion. I will use the parameter expansion to separate the digit. – tembikai Mar 28 '19 at 08:51

0 Answers0