Removing Middle of Filename

我们两清 提交于 2019-12-11 04:30:41

问题


I wish to remove the middle of filenames that look like the following:

Wm-no-Bis.GAGATTCC-ATAGAGGC.L001.R1.001.fastq.trim.R2.fastq
Pek-no-Bis.GAGATTCC-AGGCGAAG.L001.R1.001.fastq.trim.R1.fastq

To Get

Wm-no-Bis.trim.R2.fastq
Pek-no-Bis.trim.R1.fastq

As you can see the beginning and end of the files are slightly variable. I have attempted to use rename as follows:

rename 's/.*.*.*.*.*.trim.//g'
Wm-no-Bis.GAGATTCC-ATAGAGGC.L001.R1.001.fastq.trim.R2copy.fastq

This removes the entire file name except for the end. The issue is obviously my lack of understanding how to use wildcards.


回答1:


You can use this rename command:

rename -n 's/^([^.]+).*(\.trim\..*)$/$1$2/' *.fastq

When you're happy with output then remove -n option (dry-run)




回答2:


try

rename 's/\.\w+-\w+\..{4}\.R.\.\d{3}\.fastq//g'

source



来源:https://stackoverflow.com/questions/43103875/removing-middle-of-filename

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!