Shell scripting for this sequence

KINDLY HELP ME FOR SHELL SCRIPTING FOR THIS TASK.

My input file consists of thousands of sequence in this format. The given input file consists of four sequences which are starting with �>� symbol (each sequence shown in different colour for easy understanding). I have to use a command at $ prompt like mfold seq=�filename�. If the file consists of one sequence it is working well because for each sequence it generates �n� number of files.

My request is how to process all these sequences one by one in the above command by giving the filename in that command and the output for each sequence to be redirect to one directory like dir1, dir2, dir3, dir4 (four directories for these four sequences outputs) because the output of each sequence consists of �n files.

>Chr8:86884850-86884997
TCCCTGGACATTCTCTTCACTGTGGGATGAGGTAGTAGGTTGTATAGTTTTAGGGTCACA
CCCACCACTGGGAGATAACTATACAATCTACTGTCTTTCCTAAGGTGATAGAAAAATCTG
CATCCAAACAACCTCACACAGTTGATAA
>ChrX:96383583-96383703
TAAAACTATACAATCTACTACCTCATCCCACAGAGCACCAGTGTTCATCTTCAGTCTACT
TGGGCCAGCTACTTGGGTCAGGAAAAAGAATCAACCAATAATTAGCAAGAAGGAAAAATGG
>Chr15:33347613-33347720
TAAACTATACAACCTACTACCTCAACCTGGGAGCATGCAGTCACAATGGCTGGAAAGCTA
CCGTTTCTTAAGCAATGAAATTACAAGTTAGTCTTATAATTGTTCTTC
>Chr25:33347623-33347720
TACACATTTAATACGGGAAGATTATCACCACAAAATCTTTCTTGTTGCCAAGTCTAACAC
AAAAGGCTCTATAGACACTTGACGTGTGGCTACTTAGC

This want to be a solution for your problem

awk -F\> '/>/{++d;system("mkdir "d)}NF{print > (d"/"$NF)}' file

however if you expect something else please post the required output base on original data sample.

How about this awk script (process.awk):

BEGIN {
   FS=">";RS=">";ORS="";
}
$NF { d++
  system("mkdir dir"d);
  print ">"$0 > ("dir"d"/input");
  system("cd dir"d"; mfold seq=input");
}

run it with:

$ awk -f process.awk inputfile

Respected Sir,
I added some lines to the process and executing. My input file contains 5000 sequences. This program executing 1020 times. after that it is giving awk : 6: fatal error. Modification to run for 5000 times is highly appreciated. Thanks in advance.

 
BEGIN {
   FS=">";RS=">";ORS="";
}
$NF { d++
  system("mkdir dir"d);
  print ">"$0 > ("dir"d"/input");
  system("cd dir"d"; mfold SEQ=input");
  system("cd dir"d"; /home/rsankar/bin/mfold SEQ=input");
  system(cd "/home/rsankar/rna/org/org1");
  system("sh final5");
  system("rm -rf dir"d);