Using awk and/or sed to reconstruct a file

So I have a file in the following format

>*42
abssdfalsdfkjfuf
asdhfskdkdklllllllffl
eiffejcif
>2
dfhucujf
dhfjdkfhskskkkkk
eifjvujf
ddftttyy
yyy
>~
ojcufk
kcdheycjc
djcyfjf

and I would like it to output

abssdfalsdfkjfufasdhfskdkdklllllllffleiffejcif
dfhucujfdhfjdkfhskskkkkkeifjvujfddftttyyyyy
ojcufkkcdheycjcdjcyfjf

So I need to remove all the lines containing ">" and join all the lines between into a single line.

Thanks in advance!!

One way:

awk '/^[^>]/{printf $0;next}NR!=1{print "";}' file

Guru.

1 Like

Another approach, this will preserve newline in the end:

awk 'END{printf "\n"}NR==1&&/>/{next}!/>/{ORS=FS}/>/{ORS=RS;$0=""}1' file

FWIW, using GNU sed:

$ sed -n '${H;bk}; />/bk; H;b; :k {g; s/\n//g; /./ p; s/.//g; x; d};' file
abssdfalsdfkjfufasdhfskdkdklllllllffleiffejcif
dfhucujfdhfjdkfhskskkkkkeifjvujfddftttyyyyy
ojcufkkcdheycjcdjcyfjf

Maybe there is a better way than this with sed. I don't know.