grep profile ~/.aws/config | sed -ne 's/^\[profile\s\(.*\)\]/export AWS_PROFILE=\1/p'
Note: If you are on a MacOS you will discover that this doesn't work due to the fun fact Mac does't use GNU sed ! (Boo Hiss !!!!) :-)
try this instead (2 ways):
grep profile ~/.aws/config | sed -ne 's/^\[profile[[:space:]]\(.*\)\]/export AWS_PROFILE=\1/p'
grep profile ~/.aws/config | sed -ne 's/^\[profile\(.*\)\]/export AWS_PROFILE=\1/p' | sed 's/ //2'
You can install gnu sed on MacOS using homebrew like so:
brew install gnu-sed
Then the first command works.
Although there is an extra
"
at the end there you might want to drop 😉