SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash loop to count multiple words from multiple corresponding files chayan Bioinformatics 1 05-10-2019 04:24 AM
How do I remove a part of the header of a fasta file in perl? Katty1 Bioinformatics 3 05-13-2016 08:11 AM
For loop in bash terminal to concatenate fastq files rcook34 Bioinformatics 6 02-04-2016 08:41 PM
how to use bash script to make iterative loop through directory with two file types jddavis Bioinformatics 2 05-23-2013 08:02 AM
BFAST fasta2brg -f filename kursuni Bioinformatics 0 05-10-2011 12:59 PM

Reply
 
Thread Tools
Old 10-09-2019, 06:58 AM   #1
Marius
8armed
 
Location: Germany

Join Date: Dec 2010
Posts: 28
Default 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?
Marius is offline   Reply With Quote
Old 10-09-2019, 10:34 AM   #2
SNPsaurus
Registered Vendor
 
Location: Eugene, OR

Join Date: May 2013
Posts: 511
Default

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/
__________________
Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com
SNPsaurus is offline   Reply With Quote
Old 10-10-2019, 05:08 PM   #3
ungsik
Junior Member
 
Location: Korea

Join Date: Mar 2013
Posts: 1
Default

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
ungsik is offline   Reply With Quote
Old 10-11-2019, 08:25 AM   #4
pmiguel
Senior Member
 
Location: Purdue University, West Lafayette, Indiana

Join Date: Aug 2008
Posts: 2,315
Default

Quote:
Originally Posted by ungsik View Post
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
pmiguel is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 02:43 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO