I have a file of the form -
>SDF123.1 blah blah
ATCTCTGGAAACTCGGTGAAAGAGAGTAT
AGTGATGAGGATGAGTGAG...
>SBF123.1 blah blah
ATCTCTGGAAACTCGGTGAAAGAGAGTAT
AGTGATGAGGATGAGTGAG....
And I want to extract the various sections of this file into individual files (like here
I wrote the following code, but it runs too slow, as compared to when I did not have the close
command in it. I had to incorporate the close
command, since without it, I was getting the awk error - too many open files
.
Here is the code -
cat C1_animal.fasta | awk -F ' ' '{
if (substr($0, 1, 1)==">") {filename=(substr($1,2) ".fa")}
print $0 >> filename; close (filename)
}'
How can I make this code more time efficient? I am new to awk.