Can I get a little help matching a string in the below text?
The default username and password is 'user' and 'ZWiliWH8E2mV'.
I'm trying to get the string between the second set of single quotes: ZWiliWH8E2mV. This string is randomly generated, and I can only rely on the formatting, and not the ZWiliWH8E2mV. After some googling, I can match it with grep:
cat file_name | grep -oP "(?<=').*?(?=')"
but it's the 3rd match, and I'm not sure how to get to it from there. I'm open to using other tools if they're better for what I'm trying to do, but I'm not very versed in them.
I'm trying to get the string between the second set of single quotes
Using awk, you can avoid regex:
s="The default username and password is 'user' and 'ZWiliWH8E2mV'."
awk -F "'" '{print $4}' <<< "$s"
ZWiliWH8E2mV
Here we are using ' as field delimiter and 4th field in awk will give us 2nd value wrapped inside single quotes.
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