![]() |
Remove a part of a filename in a Bash loop
I have many files named like this:
lib01.GFBAG_UHAU.fastq.sam.bam lib02.ABABAB_ZU.fastq.sam.bam lib03.ZGAZG_IAUDH.fastq.sam.bam Many parts of the filenames are thus variable in length, although they are connected through the same type of punctuation (. or _). What I want to achieve is to remove the part .fastq.sam.bam from a filename when I loop trough these files in BASH. How do I achieve this in Bash? |
You want to split the string on a "." delimiter and then keep the first two parts. Or use ".fastq.sam.bam" as a delimiter, I suppose!
https://www.tutorialkart.com/bash-sh...-split-string/ |
Refer to https://unix.stackexchange.com/quest...ck-of-variable
An example for changing extension from fastq.sam.bam to txt. for file in *.fastq.sam.bam do mv ${file%.fastq.sam.bam} ${file%.fastq.sam.bam}.txt done |
Quote:
for file in *.fastq.sam.bam do mv $file ${file%.fastq.sam.bam}.txt done -- Phillip |
All times are GMT -8. The time now is 12:35 PM. |
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.