2,$G # On all but the first line, append a NEWLINE and the # contents of the Hold space to the Pattern space. h # Copy the Pattern space to the Hold space. $!d # Delete all except the last line.