![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
One line fasta file with overlapped scaffold | illinu | Bioinformatics | 4 | 09-18-2013 06:43 AM |
How to join the line wraps in FASTA file | Fad2012 | Bioinformatics | 22 | 03-21-2013 07:52 AM |
GTF file with one line per gene? | cnyh | RNA Sequencing | 3 | 03-06-2013 09:36 AM |
BFAST fasta2brg -f filename | kursuni | Bioinformatics | 0 | 05-10-2011 12:59 PM |
Add a new line after the last file recording | Wei-HD | Bioinformatics | 2 | 04-15-2010 01:13 AM |
![]() |
|
Thread Tools |
![]() |
#1 |
Member
Location: Spain Join Date: Jun 2010
Posts: 56
|
![]()
I have 1200 fasta file which are named x*. Does anybody know how to change the name of the file so that the new name is the first name of the file itself?
Example xcv.txt which has written: >contig1 CGGGTCCC I want the xcv file to be renamed as contig1 and so on for the 1200 fasta files... Thanks |
![]() |
![]() |
![]() |
#2 |
Senior Member
Location: East Coast USA Join Date: Feb 2008
Posts: 7,080
|
![]()
WARNING: Please make sure you have a copy of the files in a secure location before using the script below. If something goes wrong then you could lose a lot of data. Test with a small subset of files first.
1. Grab a list of file names you want to convert into a file (example below assumes file names end in .fq). Code:
$ ls -1 x*.fq > filelist Code:
for file in `cat ./filelist` do # Avoid renaming diretories! if [ -f "$file" ] then newname=`head -1 $file | cut -d">" -f2` if [ -f "$newname" ] then echo "Cannot rename $file to $newname - file already exists" else cp "$file" "$newname"."fq" fi fi done You can use "mv" instead of "cp" once you are sure script works to rename the files. There must be several other ways of doing this. This is just one of them ![]() Modified using code found here: https://gist.github.com/dylan-k/6531959 |
![]() |
![]() |
![]() |
#3 |
Senior Member
Location: East Coast USA Join Date: Feb 2008
Posts: 7,080
|
![]()
One-line variation. WARNING in my previous post still applies.
Code:
$ for f in *.fq; do echo mv "$f" "`head -1 $f|cut -d">" -f2`.fq"; done Note 2: If you do not want to rename then "cp" can be substituted for "mv" retaining a copy of the original files. |
![]() |
![]() |
![]() |
#4 | |
Member
Location: Spain Join Date: Jun 2010
Posts: 56
|
![]() Quote:
|
|
![]() |
![]() |
![]() |
Tags |
command line, fasta, rename |
Thread Tools | |
|
|