skip to Main Content

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ç#

2

Answers


  1. Using sed

    $ sed -E 's/.*db_password ([^ ]*).*/1/' input_file
    $£é5+dd/gcç#
    
    Login or Signup to reply.
  2. Post by HatLess will fail if password contains space. This should do:

    sed -E 's/.*db_password (.*?) --db_name.*/1/' file
    $£é5+d d/gcç#
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search