Home > Blockchain >  How to extract the password from this string in bash: "--db_host db --db_password $£é5 dd/gcç#
How to extract the password from this string in bash: "--db_host db --db_password $£é5 dd/gcç#

Time:09-28

I have tried this on Debian, but it fails:

echo "--db_host db --db_password $£é5 dd/gcç# --db_name zorgl" | sed -e "s/^.*db_password *\([^ ] \)  .*$/\1/"

Result (no match):

--db_host db --db_password $£é5 dd/gcç# --db_name zorgl

Expected result:

$£é5 dd/gcç#

CodePudding user response:

Using sed

$ sed -E 's/.*db_password ([^ ]*).*/\1/' input_file
$£é5 dd/gcç#
  • Related