【发布时间】:2026-01-11 09:45:01
【问题描述】:
我有一个带有开始和结束标记的字符串,我想在一行上打印出来。 案例是:
- 一个字符串可能会出现在一行中 - 保持原样。
- 一个字符串可以出现在多行 - 合并为一行。
- 结束标记可以出现在多行中 - 合并为一行。
比如我要改造:
(start) AAAA
(the end)
(start) BBBB (the end)
(start) CCCC (the
end)
进入输出:
(start) AAAA (the end)
(start) BBBB (the end)
(start) CCCC (the end)
目前我有这个:
awk '/^\(start\)/{printf $0" ";next;}1' test.text
(start) AAAA (the end)
(start) BBBB (the end) (start) CCCC (the end)
这个命令的问题是:
- AAAA 之后的额外空格。
- BBBB 和 CCCC 在同一条线上。
- 最后的结束标记有一个额外的空间。
对此有什么好的工具和解决方案? 对于正确方向的指针,我会很高兴。
【问题讨论】:
-
如果这真的是一个 html 文件,最好花时间学习 html 漂亮打印实用程序的选项,例如
tidy。祝你好运。 -
我向你保证它不是 HTML,谢谢。