If cpad0112's solution works, too, then let me know so that I can move it to an answer (or you can just upvote it to account for his/her efforts in helping out).
Also, if Pierre's comments were helpful, it would be beneficial to upvote them too.
I have a file contents with specific pattern, I would like to split that file into multiple file after pattern match and file name should be with after pattern match words Examples
P1_1r6r
NRVSTVQQLTKRFSLGMLQGRGPLKLFMALVAFLRFLTIPPTAGILKRWGTIKKSKAINV
LRGFRKEIGRMLNILNRRRRRVSTVQQLTKRFSLGMLQGRGPLKLFMALVAFLRFLTIP
P1_1sfk
MALVAFLRFLTIPPTAGILKRWGTIKKSKAINVLRGFRKEIGRMLNILNRRRRRVSTVQQ LTKRFSLGMLQGRGPLKLFMALVAFLRFLTIPPTAGILKRWGTIKKSKAINVLRGFRKEI
P1_12562
RFSLPLKLFMALVAFLRFLTIPPTAGILKRWGTIKKSKAINVLRGFRKEIGRM LNILNRRRRRVSTVQQLTKRFSLGMLQGRGPLKLFMALVAFLRFLTIPPTAGILKRWGTI
So, here pattern is P1, I want to split the above file into 3 different files contenst with file name like 1r6r,1sfk,12562.
Thanks
Maybe this is the desired output?
File: 1r6r
NRVSTVQQLTKRFSLGMLQGRGPLKLFMALVAFLRFLTIPPTAGILKRWGTIKKSKAINV
LRGFRKEIGRMLNILNRRRRRVSTVQQLTKRFSLGMLQGRGPLKLFMALVAFLRFLTIP
File: 1sfk
MALVAFLRFLTIPPTAGILKRWGTIKKSKAINVLRGFRKEIGRMLNILNRRRRRVSTVQQ
LTKRFSLGMLQGRGPLKLFMALVAFLRFLTIPPTAGILKRWGTIKKSKAINVLRGFRKEI
File: 12562
RFSLPLKLFMALVAFLRFLTIPPTAGILKRWGTIKKSKAINVLRGFRKEIGRM
LNILNRRRRRVSTVQQLTKRFSLGMLQGRGPLKLFMALVAFLRFLTIPPTAGILKRWGTI
Assuming that the data is in MyProtein.fasta, this can produce this output (assuming FASTA headers as '>P1_1r6r', '>P1_1sfk', et cetera):
awk -F"_" '/^>P1/ {file=$2; printf "" > file}; !/^>P1/ {print >> file}' MyProtein.fasta
If the headers are just 'P1_1r6r', 'P1_1sfk', et cetera' (without the greater than symbol):
awk -F"_" '/^P1/ {file=$2; printf "" > file}; !/^P1/ {print >> file}' MyProtein.fasta
If cpad0112's solution works, too, then let me know so that I can move it to an answer (or you can just upvote it to account for his/her efforts in helping out).
Also, if Pierre's comments were helpful, it would be beneficial to upvote them too.
Log in to answer this question.
your input format is not clear . is it fasta ?
probably a duplicate of How To Split One Big Sequence File Into Multiple Files With Less Than 1000 Sequences In A Single File ; How To Split A Multiple Fasta ; ...
with awk and sed: Input:
command:
output:
Note: All AA are in single line post identifier (each 2nd line after identifier)