Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
sed 命令 'H' 在先将新行附加到保持空间后,从模式空间附加到保持空间。
如何在不将新行插入保持空间的情况下追加?
有一些技巧,这取决于你的目标。例如,您可以使用h第一行并在每个H输入之后或末尾删除新行...
h
H
删除每个附加:
seq -w 10 | sed -n 'H;x;s/\n//g;x;${x;p}'
最后删除:
seq -w 10 | sed -n '1h;1!{H};${x;s/\n//g;p}'
诀窍是使用x(交换保持和模式空间的内容)并删除换行符。
x