When I execute a specific command I obtain as output 2 values, like this:
2.056000 640.640015
I want to extract only the second value, and assign it to a variable, to use later.
Can anyone help me?
If you want a variable to contain the result of a command, var=$(command)
is the solution.
In your case,
your_var=$(your_command | awk '{print $2}')
You have to perform the command and then pipe it to awk
, that will get the second parameter.
Fedorqui's approach is good, but for the sake of providing an alternative:
your_command | read DONT_CARE YOUR_VAR IGNORE_ANYTHING_TRAILING
This has the benefit of not needing to run up a subshell and awk. Tested and working for zsh. You don't have to bother with the IGNORE_ANYTHING_TRAILING, but then say your_command spat out 1 2 3 4, YOUR_VAR would end up with "2 3 4".