Substitution with sed + bash function

后端 未结 7 2114
一向
一向 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 03:00

    do it step by step. (also you could use an alternate delimiter , such as "|" instead of "/"

    function parseDates(){
        #Some process here with $1 (the pattern found)
        return "dateParsed;
    }
    
    value=$(parseDates)
    sed -n "s|[0-3][0-9]/[0-1][0-9]/[0-9][0-9]|& $value &|p" myfile
    

    Note the use of double quotes instead of single quotes, so that $value can be interpolated

提交回复
热议问题