something like this?
kent$ awk '/^key.:/{p=1}/^name:/{p=0}
{if(p)printf "%s",$0;else printf "%s%s\n", (NR==1?"":RS),$0}' file
name: charles
key1: howareyou?
name: erika
key2: I'mfine,thanks
name: ...
handle the spaces:
awk '/^key.:/{p=1}/^name:/{p=0}
{if(p)printf "%s%s",(/^key.:/?"":" "),$0;
else printf "%s%s\n", (NR==1?"":RS),$0}' file
output:
name: charles
key1: how are you?
name: erika
key2: I'm fine, thanks
name: ...
2
solved Remove newlines between two words