sed '
s/^ *//
t loop
:loop
$b
N
s/ *\n *CAR /\
CAR /
t p
s/ *\n */ /
t loop
:p
P
s/.*\n//
t loop
' in_file >out_file
Narrative: Clean leading spaces off the first line, branch to the target to clear the branch flag, create a loop back branch target, exit at EOF printing last line, get a second line into the buffer, if it is a CAR line just clean it up and branch to print first line, remove first line, and loop. If not a CAR line, turn the linefeed and any adjacent spaces into a space and loop. I call this a classic looper in sed, where you merge lines but have to deal with the next group or EOF. Note that a) it assumed the first line is a CAR line, and B) it checks for 'CAR ', not just 'CAR', so as not to be fooled by substrings of other words.
awk ' {
$1 = $1
A[++n] = $0
} END {
for ( i = 1; i <= n; i++ ) {
if ( A ~ /CAR/ ) {
A = ( i == 1 ? A FS : RS A FS )
printf A
}
else
{
A = ( i == n ? A RS : A FS )
printf A
}
}
}' filename