Hey Zoe, bPrint is just a boolean flag that I created myself.
I'll break the command into pseudo code:
Matching header
if (/^>/ && /OS=Homo sapiens/) {bPrint=1; split($0, a, " OS="); split(a[1], b, "|"); print ">"b[2]" "b[3]};
If the line begins with '>' AND contains 'OS=Homo sapiens', set bPrint to 'TRUE' and then split/print the header out
Non-matching header
if (/^>/ && !/OS=Homo sapiens/) {bPrint=0};
If the line begins with '>' AND does NOT contain 'OS=Homo sapiens', set bPrint to 'FALSE'
Line of sequence following a matching header
if (!/^>/ && bPrint==1) print $0}'
If the line does NOT begin with '>' AND bPrint is 'TRUE', print the line
If there are empty lines, it will just print them.
Thank you very much Kevin. I'm new to bash, I understand from your code how you separate the line and only print either side of the '|' with the 'split(a[1], b, "|"); print ">"b[2]" "b[3]}'. Can you explain what the bprint is doing??
Hey Zoe, could you repost this as a comment to my answer? Just to maintain fluidity of the thread. You can delete this and then re-post above. I have answered your comment already there!
Awesome, thank you Kevin!
Please use
ADD COMMENTorADD REPLYto answer to previous reactions, as such this thread remains logically structured and easy to follow. I have now moved your post but as you can see it's not optimal. Adding an answer should only be used for providing a solution to the question asked.If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.