Pad numerical values in filename with three digit value using sed

前端 未结 3 549
故里飘歌
故里飘歌 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:25

    This might work for you (GNU sed):

    sed  -r 's/[0-9]+/$(printf "%03d" &)/g;s/.*/echo "&"/e' file
    Test 001.txt
    Test v002 001.txt
    

提交回复
热议问题