Can someone suggest how can I do the follwing:
`
attributes:
0x00000007 <blob>="Test"
0x00000008 <blob>=<NULL>
"acct"<blob>="abc@xyz.com"
password: "mycrypticpassword"
`
If I want to extract abc@xyz.com and the password value and assign them to variables in a shell script, can it be done in perl or sed?
Thanks
Using sed with backreference:
$ email=$(sed -n 's/[\t ]*"acct"<blob>="\([^"]*\)"/\1/p' file)
$ pass=$(sed -n 's/[\t ]*password: "\([^"]*\)"/\1/p' file)
$ echo $email
abc@xyz.com
$ echo $pass
mycrypticpassword
Extract the required value using Perl:
$ perl -nle 'print "$1$2" if /"acct"<blob>="(.*)"|password: "(.*)"/' file
abc@xyz.com
mycrypticpassword
grab the output using $(...)
construct, and assign it to two variables using read EMAIL PASSWORD <<< ...
:
$ read EMAIL PASSWORD <<< \
> $(perl -nle 'print "$1$2" if /"acct"<blob>="(.*)"|password: "(.*)"/' file)
$ echo $EMAIL
abc@xyz.com
$ echo $PASSWORD
mycrypticpassword
User contributions licensed under CC BY-SA 3.0