使用linux shell命令将多行输出合并为一行,重新格式化报告文件
我有一个包含以下输入的文件:使用linux shell命令将多行输出合并为一行,重新格式化报告文件,linux,sed,awk,format,Linux,Sed,Awk,Format,我有一个包含以下输入的文件: 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
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