其他分享
首页 > 其他分享> > sed 如何每两行合并为一行

sed 如何每两行合并为一行

作者:互联网

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.



		

标签:两行,space,pattern,一行,sed,input,hold,contents
来源: https://blog.csdn.net/qq_38963393/article/details/122023245