sed '$!N;s/\n/ /' infile # 如果不是最后一行,就追加下一行,并去掉当前行的换行符
sed 'h;n;H;x;s/\n/ /' infile #
# sed command list:
N
Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands.
h
(hold) Replace the contents of the hold space with the contents of the pattern space.
n
(next) If auto-print is not disabled, print the pattern space, then, regardless, replace the pattern space with the next line of input. If there is no more input then sed exits without processing any more commands.
H
Append a newline to the contents of the hold space, and then append the contents of the pattern space to that of the hold space.
x
Exchange the contents of the hold and pattern spaces.