The regex matched in the second set of brackets is referenced by the \2
echo "user=clarkeb role=admin" | sed 's/\w*=\(\w*\) \w*=\(\w*\)/\1/'
Will output clarkeb
echo "user=clarkeb role=admin" | sed 's/\w*=\(\w*\) \w*=\(\w*\)/\2/'
Will output admin
echo "user=clarkeb role=admin" | sed 's/\w*=\(\w*\) \w*=\(\w*\)/\1 \2/'
Will output clarkeb admin
Therefore, outputs can be assigned to variables as you'd expect ...
myUser=$(echo "user=clarkeb role=admin" | sed 's/\w*=\(\w*\) \w*=\(\w*\)/\1/')
or
myUser=`echo "user=clarkeb role=admin" | sed 's/\w*=\(\w*\) \w*=\(\w*\)/\1/'`
No comments:
Post a Comment