-n - don't automatically print lines
x; - swap the current pattern space (in this case, the whole line just read) with the 'hold' buffer. When the first line is processed this swaps the 'A' line into 'hold' and has nothing in the pattern space, for the second line it swaps the 'B' line into 'hold and the 'A' line back into the pattern space, and so on.
$s/ |.*// - on processing the last line, replace (in the pattern space) ' |' followed by any number of any character with nothing. (Note that the replace is actually happening on the last-but-one line, since it was just swapped out of hold.)
1!p; - on processing any line except the first, print the pattern space (which is now the previous line).
${x;p} - on processing the last line, swap the hold & pattern space again (which gets the actual last line back) and print the pattern space.
Hopefully that makes sense. It's late
.