简体   繁体   中英

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 > ?

ie

>A13P0
ACCATAGAGAGCCCGAGATTTA
>03HK2
ACACAGTGTGTTTAGAGGGAGA

thanks!

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

See Specifying file to process to Perl one-liner for usage.

I know this has been asked/answered a thousand times but I can't find it so:

$ awk '/^>/{print (NR>1?ORS:"") $0; next} {printf "%s", $0} END{print ""}' file
>A13P0
ACCATAGAGAGCCCGAGATTTA
>03HK2
ACACAGTGTGTTTAGAGGGAGA

使用perl命令行:

perl -pE '$.>1 && !s/^>/\n>/ && chomp; END{say}' file

With sed :

$ sed ':a;$!N;/>/!{s/\n\([^>]\)/\1/;ta};P;D' file
>A13P0
ACCATAGAGAGCCCGAGATTTA
>03HK2
ACACAGTGTGTTTAGAGGGAGA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM