Can not extract the capture group with neither sed nor grep

后端 未结 5 1751
猫巷女王i
猫巷女王i 2021-01-30 08:16

I want to extract the value pair from a key-value pair syntax but I can not.
Example I tried:

echo employee_id=1234 | sed \'s/employee_id=\\([0-9]+\\)/\\1/         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 09:15

    You are specifically asking for sed, but in case you may use something else - any POSIX-compliant shell can do parameter expansion which doesn't require a fork/subshell:

    foo='employee_id=1234'
    var=${foo%%=*}
    value=${foo#*=}
    

     

    $ echo "var=${var} value=${value}"
    var=employee_id value=1234
    

提交回复
热议问题