probably simple question for someone who knows, but I’m having a hard time retrieving some variable values from a file. My file is something like:
variable1 12
variable2 43
variable3 897
and I want to get the value of variable2, 43.
I tried some commands with sed but with no luck:
sed -n 's/variable2 //;s/variable3//' myFile
With only
sed:Your problem is you are using
-nto suppress the output ofsedso you need thepflag sosedprints the lines where the substitution took place.As this just pattern matching I would go with only grep for this:
Or even just
awk: