This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Separate lines based on some character?

I have a fasta file like below, I like to seprate only coordinate and add one column with "hello" name.

>Human|chr16:80372593-80373755 | element 4 | positive  | neural tube[6/10] | hindbrain (rhombencephalon)[10/10] | midbrain (mesencephalon)[10/10]
gtgaCAGAGACAGACAGTGACAGAGACAgattttagaatttgaacaaaggtaaataagag

>Human|chr16:78510608-78511944 | element 12 | positive  | hindbrain (rhombencephalon)[9/11] | forebrain[9/11]
AAGCTAGCTAATTGCTTCTTCAGTTGaagacctaaatgagttttaaagtgaaatgcatat

Expect file:

chr16:80372593-80373755         hello
chr16:78510608-78511944         hello
r linux fasta

what do you consider 'name' (== which of the fields in your fasta header?)

I like to add my favorite name.

Will change for each entry or stay the same?

it is the same name.

1 answer

awk -F '|' '/^>/ { print $2 "\thello"}' jeter.fa

If you get annoyed by the extra space after chr16:80372593-80373755 :

awk -F '|' '/^>/ { print substr($2, 1, length($2)-1) "\thello"}' jeter.fa

Yes it is quicker, but if they got a space in the id name the command fails

Log in to answer this question.