2017-04-20 68 views

回答

0

使用sed的後向引用:

$ email=$(sed -n 's/[\t ]*"acct"<blob>="\([^"]*\)"/\1/p' file) 
$ pass=$(sed -n 's/[\t ]*password: "\([^"]*\)"/\1/p' file) 
$ echo $email 
[email protected] 
$ echo $pass 
mycrypticpassword 
0

使用Perl提取所需的值:

$ perl -nle 'print "$1$2" if /"acct"<blob>="(.*)"|password: "(.*)"/' file 
[email protected] 
mycrypticpassword 

搶使用$(...)結構的輸出,並將其分配給使用read EMAIL PASSWORD <<< ...兩個變量:

$ read EMAIL PASSWORD <<< \ 
> $(perl -nle 'print "$1$2" if /"acct"<blob>="(.*)"|password: "(.*)"/' file) 
$ echo $EMAIL 
[email protected] 
$ echo $PASSWORD 
mycrypticpassword