1

I need to start a new line based on a specific string and add the lines between those strings onto the same line.

Input:

Gator_locus100 

AGTCGTGTAGATGATAGTCGATGATGGATGANNNNGTACGT
GCTCAGTCGTGCTCGTCGATCGATCGTCAGCTCGATCGATCGATCGATCGACTCGATCG
GCTCGATCGATCGATC

Gator_locus101

ATCGATCGATCGATCGATCGATCGATCGATCGAT
GCAGTCGATCGATACGATCGATACGACTACGA
TCGATCGATCGCATCGATCGATCGACTC

Gator_locus102
NNNNNNNNNGCTCAGTCGATCGATCGCATCGATCGACTACGTACGATCGATCAGCATCAG
GCTCAGTCGTGCTCGTCGATCGATCGTCAGCTCGATCGATCGATCGATCGACTCGATCG
GACTCAGATCGATGACTACGATCAGATCGATAACGATCAGTACGACTACGATCAGCATCAGAT
NNNNNNNNNNNNNNNNNNNNNGACTACGACATCGATCAGACTCAGACGT

Ouput:

Gator_locus100  AGTCGTGTAGATGATAGTCGATGATGGATGANNNNGTACGTGCTCAGTC....

Gator_locus101 ATCGATCGATCGATCGATCGCGATGCAGTCGATCGATACGATCGATACG....

Gator_locus102 NNNNNNNNNGCTCAGTCGATCGATCGCATCGATCGACTACGTACGATC .....

How to do this?

1

awk solution:

awk -v ORS= '/Gator_/{ if (NR > 1) print RS RS }1; END{ print RS }' file

The output:

Gator_locus100 AGTCGTGTAGATGATAGTCGATGATGGATGANNNNGTACGTGCTCAGTCGTGCTCGTCGATCGATCGTCAGCTCGATCGATCGATCGATCGACTCGATCGGCTCGATCGATCGATC

Gator_locus101ATCGATCGATCGATCGATCGATCGATCGATCGATGCAGTCGATCGATACGATCGATACGACTACGATCGATCGATCGCATCGATCGATCGACTC

Gator_locus102NNNNNNNNNGCTCAGTCGATCGATCGCATCGATCGACTACGTACGATCGATCAGCATCAGGCTCAGTCGTGCTCGTCGATCGATCGTCAGCTCGATCGATCGATCGATCGACTCGATCGGACTCAGATCGATGACTACGATCAGATCGATAACGATCAGTACGACTACGATCAGCATCAGATNNNNNNNNNNNNNNNNNNNNNGACTACGACATCGATCAGACTCAGACGT
  • How would you add a comma or some other type of field delimiter between Gator_locus*** and the sequence? – Josh Mar 13 '18 at 15:18
  • @Josh, awk -v ORS= '/Gator_/{ $0=$0","; if (NR > 1) print RS RS }1; END{ print RS }' file – RomanPerekhrest Mar 13 '18 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.