Batch remove substring from filename with special characters in BASH

前端 未结 2 485
渐次进展
渐次进展 2021-01-20 15:01

I have a list of files in my directory:

opencv_calib3d.so2410.so
opencv_contrib.so2410.so
opencv_core.so2410.so
opencv_features2d.so2410.so
opencv_flann.so24         


        
相关标签:
2条回答
  • 2021-01-20 15:41
    a='opencv_calib3d.so2410.so'
    echo "${a%%.so*}${a#*.so}"
    opencv_calib3d2410.so
    

    Where:

    • ${a%%.so*} - the part before the first .so
    • ${a#*.so} - the part after the first .so
    0 讨论(0)
  • 2021-01-20 16:03

    Try this in your mv command:

    mv "$f" "${f/.so/}"
    

    First match of .so is being replaced by empty string.

    0 讨论(0)
提交回复
热议问题