我有一个包含以下输入的文件:
name: ted
position:11.11.11.11"
applicationKey:88
channel:45
protocol:4
total:350
name:janet
position:170.198.80.209
applicationKey:256
channel:44
protocol:4
total:1
我喜欢这样的输出
tedd 11.11.11.11 88 45 4 350
janet 170.198.80.209 256 44 4 1
有人可以帮忙吗?
最佳答案
这应该有效:
awk -F':' '{printf "%s %s",$2,ORS=NF?"":"\n"}END{print "\n"}' file
$ cat file
name:ted
position:11.11.11.11
applicationKey:88
channel:45
protocol:4
total:350
name:janet
position:170.198.80.209
applicationKey:256
channel:44
protocol:4
total:1
$ awk -F':' '{printf "%s %s",$2,ORS=NF?"":"\n"}END{print "\n"}' file
ted 11.11.11.11 88 45 4 350
janet 170.198.80.209 256 44 4 1
关于linux - 使用 linux shell 命令将多行输出合并为一行重新格式化报告文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22053868/