【发布时间】:2017-04-08 01:05:32
【问题描述】:
我有一个看起来像这样的文件:
t2_this_is_some_output_80_pool
address 12.34.56.78
state down
address 13.34.56.78
state down
t2_this_is_a_different_output_80_pool
address 14.34.56.78
t2_this_is_another_output_80_pool
address 15.34.56.78
state up
我想输出它,所以它看起来像:
t2_this_is_some_output_80_pool address 12.34.56.78 state down
t2_this_is_some_output_80_pool address 13.34.56.78 state down
t2_this_is_a_different_output_80_pool address 14.34.56.78
t2_this_is_another_output_80_pool 15.34.56.78 state up
我一直在尝试使用 BASH、awk 和 sed,但我所做的一切都无法为我提供所需的输出。
我尝试过的事情之一:
用 = 替换开头的 12 个空格,如果行以 = 开头,则追加到上一行
cat file.txt | sed 's/ /=/' | sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
但这不起作用...
任何帮助都会得到很大的帮助:-)
【问题讨论】:
-
我很确定 sed 可以解决问题。
-
请显示 bash、awk 或 sed 尝试,以便我们在您遇到问题的地方提供帮助。
-
已更新。我粘贴在帖子的第一个 daft 中,而不是第二个 face palm