linux - 使用 linux shell 命令将多行输出合并为一行重新格式化报告文件

标签 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 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/

相关文章:

awk - 处理两个文件时在 AWK 中使用数组

python - platform.system 和 platform.linux_distribution 究竟输出什么?

regex - 更正 bash sed 命令语法以获得正确的子字符串

bash - 访问 $?带有管道语句的变量?

awk - 文本文件中的算术替换

Linux - Bash 将字符串重定向到文件

awk - 匹配文件中的字符串并仅打印匹配的第一行

linux - 移动已编译的 Haskell 程序

linux - lua:bad argument #2 to '?' (起始索引越界)

linux - bash -错误 : Syntax error: operand expected (error token is "testdir/.hidd1/")