user2886545
user2886545

Reputation: 713

AWK: splitting a string into pieces

I've been trying to solve this problem by myself, I've looked for some help on Google, but I can't go ahead anyway. Any help you can provide will be very thanked!

So, I have a string, for example:

CTGGCAAGAAAGAAATGTGGAATGGCAACAAAGAAAGGAAAAAAAATCAATACTGGCTGATGCAGTTTC

And I'm looking for this output:

CTG GCA AGA AAG AAA TGT GGA ATG GCA ACA AAG AAA GGA AAA AAA ATC AAT ACT GGC TGA TGC AGT TTC

I could do it very fast in Python or Perl, but I need to use here AWK.

Thank you very much, people! I appreciate.

Upvotes: 2

Views: 96

Answers (1)

glenn jackman
glenn jackman

Reputation: 246807

awk '{gsub(/.../,"& ")}1' <<< CTGGCAAGAAAGAAATGTGGAATGGCAACAAAGAAAGGAAAAAAAATCAATACTGGCTGATGCAGTTTC
CTG GCA AGA AAG AAA TGT GGA ATG GCA ACA AAG AAA GGA AAA AAA ATC AAT ACT GGC TGA TGC AGT TTC 

Upvotes: 6

Related Questions