I have a script which produces the following output:
[RESPONSE] code = 211 description = Domain name not available queuetime = 0 runtime = 0.009
I need to assign only the code = 211 part to a variable. How will I do that?
I have a script which produces the following output:
[RESPONSE] code = 211 description = Domain name not available queuetime = 0 runtime = 0.009
I need to assign only the code = 211 part to a variable. How will I do that?
If you wish to store code = 211 to a variable say var do this :
$ var="$(./your_script | sed -E 's/.*(code = [[:digit:]]+).*/\1/')"
$ echo "$var"
code = 211
Instead, if you wish to assign 211 to code given the result of the script:
$ eval "$(./your_script | sed -E 's/.*(code = [[:digit:]]+).*/\1/;s/ //g')"
$ echo "$code"
211
Notes
s/.*(code = [[:digit:]]+).*/ retains the code = number part of the results/ //g deletes the spaces around = so that code=number is passed to eval#Assuming there is space between [response] and code.Seems there is from your example.
var=$(./yourScript.sh |awk '{print $2,$3,$4}')
echo $var
code = 211