How to use sed to change file extensions?

前端 未结 6 766
粉色の甜心
粉色の甜心 2021-01-01 06:33

I have to do a sed line (also using pipes in Linux) to change a file extension, so I can do some kind of mv *.1stextension *.2ndextension like mv *.txt *.

6条回答
  •  粉色の甜心
    2021-01-01 07:19

    you can use string manipulation

    filename="file.ext1"
    mv "${filename}" "${filename/%ext1/ext2}"
    

    Or if your system support, you can use rename.

    Update

    you can also do something like this

    mv ${filename}{ext1,ext2}
    

    which is called brace expansion

提交回复
热议问题