Extract key info from CLI

Ooops just noticed that sed command on the URL only removed the first double quote.

Small tweak required when I reread man sed

thats better note the ‘g’

willie@gagarin:~$ MY_SAFE_KEY_URL=$(awk '{if(NR==1) print $4}' keys.txt|sed 's/"//g')
willie@gagarin:~$ echo $MY_SAFE_KEY_URL 
safe://hyryyyyyyk7xrd6yqzcpd8a69g1zxp85pdfzimiudfnkxyigcmi7hsa38seuy
2 Likes
sed 's/"//'

Could a ‘g’ be missing?

sed 's/"//g'

EDIT: Oops. I tried to be a smartass, but too late.

1 Like

yep see edited post above :slight_smile:

1 Like

No - you were trying to help - thank you :slight_smile:

1 Like

In all honesty, it was a bit of both.

1 Like

You could also use the --json flag of CLI, with perhaps the jq tool, e.g.:

$ safe keys create --json | jq .[0]
"safe://hyryyyyyypgogf65ki5js49xqhzj9qkopxsuyoxjmxzw1m35xpk8fmyaz5xho"

$ safe keys create --json | jq .[1] > keypair.txt

$ safe keys create --json | jq .[1][0] > pk.txt

$ safe keys create --json | jq .[1][1] > sk.txt
2 Likes

Yeah, jq is great. I use it a lot, even just piping through and doing a jq . to get a ‘pretty print’ is very handy.

I never remember how to use its querying language though.

1 Like

grep -i “safekey *created” | sed “s~.*://~~; s~\”~~"

This will get you the key from the output (file) and saves using awk and jq. Just uses grep and sed and is fastest way

1 Like

At first glance this looks like an OK series of tutorials

Unlike many perfectly competent and grammatically correct presenters from the Indian sub-continent, this guy is actually quite intelligible.
Many tutorials are spoilt for me because I find it very difficult to get my ears around the Indian accent even though they are speaking quite correct English.

Cheers! Although I’m a reader, so I always prefer a book for learning something like a programming language.

1 Like