Reputation: 9752
Hi I have the following file:
>101
ADFGLALAL
GHJGKGL
>102
ASKDDJKJS
KAKAKKKPP
>103
AKNCPFIGJ
SKSK
etc etc;
and I need it in the following format:
>101
ADFGLALALGHJGKGL
>102
ASKDDJKJSKAKAKKKPP
>103
AKNCPFIGJSKSK
how can I do this? perhaps a perl one liner?
Thanks very much!
Upvotes: 1
Views: 142
Reputation: 97938
perl -npe 'chomp if ($.!=1 && !s/^>/\n>/)' input
Remove the newline at the end (chomp
) if there is no >
at the beginning (!s/^>/\n>/
is false). Also, add a newline at the beginning of the line if this is not the first line ($.!=1
) and there is a >
at the beginning of the line (s/^>/\n>/
).
Upvotes: 1
Reputation: 185025
perl -lne '
if (/^>/) {print}
else{
if ($count) {
print $string . $_;
$count = 0;
} else {
$string = $_;
$count++;
}
}
' file.txt
Upvotes: 0