Pad numerical values in filename with three digit value using sed

前端 未结 3 512
故里飘歌
故里飘歌 2021-01-22 17:47

I am passing a filename into my bash script and cleaning the name using sed. A few sample files would be:

Test 01.txt
Test v2 01.txt

I would

3条回答
  •  孤街浪徒
    2021-01-22 18:02

    Instead of

    sed -r -e 's/\d+/sprintf("%03d",$&)/e'
    

    use

    perl -pe 's/\d+/sprintf("%03d",$&)/ge'
    

提交回复
热议问题