Skip to main content
already received in answer
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?

Edit: Solution thanks to @jasonwryan and @KasiyA

variable=$([program call])

read var1 var2 <<< $(awk -F"[)(, ]" '{printf "%s\n%s\n", $(NF-3),$(NF-1)}' <<< "$variable")

echo "val1 = $var1"
echo "val2 = $var2"

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?

Edit: Solution thanks to @jasonwryan and @KasiyA

variable=$([program call])

read var1 var2 <<< $(awk -F"[)(, ]" '{printf "%s\n%s\n", $(NF-3),$(NF-1)}' <<< "$variable")

echo "val1 = $var1"
echo "val2 = $var2"

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?

added 238 characters in body
Source Link
Matty
  • 67
  • 2
  • 7

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?

Edit: Solution thanks to @jasonwryan and @KasiyA

variable=$([program call])

read var1 var2 <<< $(awk -F"[)(, ]" '{printf "%s\n%s\n", $(NF-3),$(NF-1)}' <<< "$variable")

echo "val1 = $var1"
echo "val2 = $var2"

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?

Edit: Solution thanks to @jasonwryan and @KasiyA

variable=$([program call])

read var1 var2 <<< $(awk -F"[)(, ]" '{printf "%s\n%s\n", $(NF-3),$(NF-1)}' <<< "$variable")

echo "val1 = $var1"
echo "val2 = $var2"
Source Link
Matty
  • 67
  • 2
  • 7

Get two values from command output in a bash script

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this.

a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391)

And in case of invalid parameters or errors the program can show different error-messages.

Is there a safe way to parse the two volt-values and store them in two variables in a bash script?