Substitution with sed + bash function

后端 未结 7 1996
一向
一向 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:41

    I'd like to know if there's a way to do this too. However, for this particular problem you don't need it. If you surround the different components of the date with ()s, you can back reference them with \1 \2 etc and reformat however you want.

    For instance, let's reverse 03/04/1973:

    echo 03/04/1973 | sed -e 's/\([0-9][0-9]\)\/\([0-9][0-9]\)\/\([0-9][0-9][0-9][0-9]\)/\3\/\2\/\1/g'
    

提交回复
热议问题