Using sed and grep/egrep to search and replace

前端 未结 6 826
小鲜肉
小鲜肉 2020-11-30 16:47

I am using egrep -R followed by a regular expression containing about 10 unions, so like: .jpg | .png | .gif etc. This works well, now I would like

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 17:22

    Honestly, much as I love sed for appropriate tasks, this is definitely a task for perl -- it's truly more powerful for this kind of one-liners, especially to "write it back to where it comes from" (perl's -i switch does it for you, and optionally also lets you keep the old version around e.g. with a .bak appended, just use -i.bak instead).

    perl -i.bak -pe 's/\.jpg|\.png|\.gif/.jpg/
    

    rather than intricate work in sed (if even possible there) or awk...

提交回复
热议问题