Skip to content

Instantly share code, notes, and snippets.

@cxhercules
Created February 12, 2019 22:50
Show Gist options
  • Save cxhercules/964903ec0511a1552cc68f3df7ceb877 to your computer and use it in GitHub Desktop.
Save cxhercules/964903ec0511a1552cc68f3df7ceb877 to your computer and use it in GitHub Desktop.
awk run system command against field
#!/bin/bash
cat secrets-alone.yml |awk -F: '{ printf "export %s=",$1; system ("echo "$2"|base64 -d "); system("echo")}'
@cxhercules
Copy link
Author

cxhercules commented Feb 12, 2019

This will work against input like following:

AWS_ACCESS_KEY_ID: dGVzdAo=
AWS_SECRET_ACCESS_KEY: c2VjcmV0Cg==
DB_URL: cG9zdGdyZXNxbDovL3VzZXI6c2VjcmV0QGRiLW5hbWUuc29tZXRoaW5nLnVzLXdlc3QtMi5yZHMuYW1hem9uYXdzLmNvbTo1NDMyL2RiCg==

And actually this example above will work without the extra echo.
cat secrets.yml |awk -F: '{ printf "export %s=",$1; system ("echo "$2"|base64 -d ")}'

But when getting output from kubernetes secrets you will need that extra echo to give newline. At least that is one way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment