I have a bash script that uses expect inside the bash script. This bash script will prompt for a password inside the expect part of the script and then return some output. I want to take that output and parse it so that it only displays a part of the output to me and stores that in a variable that the normal bash script can use. My script is:
#!/bin/sh
output=$(
/usr/bin/expect << EOF
spawn -noecho generate passcode -a 123456789
expect "passphrase:" { send "password\n" }
expect eof
EOF
#)
) | awk '/^ [a-zA-Z]*: (\S+)/'
echo $output
The output that I get without the awk regex is:
Passcode: 543245324532455464
My regex will parse the output and only store the 543245324532455464
value in the output variable. That is what I hoped it would do. If I append the | awk '/^ [a-zA-Z]*: (\S+)/'
to the end of the command, it returns nothing, just blank. If I take it off, it returns the output I expect.
Can anyone tell me how I can get the correct data stored into my variable in bash?