brucezepplin brucezepplin - 6 months ago 10
Perl Question

how to merge lines that do not begin with certain character

if i have the following:

>A13P0
ACCATAGAGAG
CCCGAGATTTA
>03HK2
ACACAGTGTGT
TTAGAGGGAGA


How do I merge lines that do not begin with
>
?

i.e.

>A13P0
ACCATAGAGAGCCCGAGATTTA
>03HK2
ACACAGTGTGTTTAGAGGGAGA


thanks!

Answer
perl -ne'
   if (/^>/) {
      print("\n") if $. != 1;
   } else {
      chomp;
   }
   print;
} {
   print("\n") if $. != 1;
'

usage:

perl -ne'...' file.in             # Outputs to STDOUT.
perl -ne'...' file.in >file.out   # Outputs to a file.
perl -i~ -ne'...' file            # Edits file "in-place" with backup.
perl -i -ne'...' file             # Edits file "in-place" without backup.
Comments