Say I have a string:
random text before authentication_token = 'pYWastSemJrMqwJycZPZ', gravatar_hash = 'd74a97f
I want a shell command to extract everything after "authentication_token = '" and before the next '.
So basically, I want to return pYWastSemJrMqwJycZPZ.
How do I do this?
Use parameter expansion:
#!/bin/bash
text="random text before authentication_token = 'pYWastSemJrMqwJycZPZ', gravatar_hash = 'd74a97f"
token=${text##* authentication_token = \'} # Remove the left part.
token=${token%%\'*} # Remove the right part.
echo "$token"
Note that it works even if random text contains authentication token = '...'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With