Substitution with sed + bash function

后端 未结 7 2109
一向
一向 2021-01-03 02:26

my question seems to be general, but i can\'t find any answers.

In sed command, how can you replace the substitution pattern by a value returned by a simple bash fun

7条回答
  •  情书的邮戳
    2021-01-03 02:52

    You can glue together a sed-command by ending a single-quoted section, and reopening it again.

    sed -n 's|[0-3][0-9]/[0-1][0-9]/[0-9][0-9]|& '$(parseDates)' &|p' datefile
    

    However, in contrast to other examples, a function in bash can't return strings, only put them out:

    function parseDates(){
        # Some process here with $1 (the pattern found)
        echo dateParsed
    }
    

提交回复
热议问题