Removing Middle of Filename

2019-07-31 13:06发布

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.

2条回答
做自己的国王
2楼-- · 2019-07-31 13:38

try

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

source

查看更多
Root(大扎)
3楼-- · 2019-07-31 13:42

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)

查看更多
登录 后发表回答