SEQanswers

SEQanswers (http://seqanswers.com/forums/index.php)
-   Bioinformatics (http://seqanswers.com/forums/forumdisplay.php?f=18)
-   -   Remove a part of a filename in a Bash loop (http://seqanswers.com/forums/showthread.php?t=91239)

Marius 10-09-2019 06:58 AM

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?

SNPsaurus 10-09-2019 10:34 AM

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/

ungsik 10-10-2019 05:08 PM

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

pmiguel 10-11-2019 08:25 AM

Quote:

Originally Posted by ungsik (Post 228840)
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

Don't you mean:

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 07:29 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.