处理多个文件,提取多个匹配项并打印(保存)到文件

处理多个文件,提取多个匹配项并打印(保存)到文件

我正在尝试解析多个文件以创建摘要报告。每个文件包含多行感兴趣的行,我想将它们组合成一行。每个文件都包含我匹配的以下数据集:

connect *changing value*
*changing value* #0x *changing value* 
*changing value* #0x *changing value*
*changing value* #0x *changing value*
*changing value* #0x *changing value*

我的粗略命令行如下

cat * | grep -E "#0x|connect" | awk '/connect/{CON=$0;next } /#0x/{ print CON "," $0}'

但这只结合了每个文件的四个匹配项的格式,从而导致

connect <changing value> , <changing value> #0x <changing value>
connect <changing value> , <changing value> #0x <changing value>
connect <changing value> , <changing value> #0x <changing value>
connect <changing value> , <changing value> #0x <changing value>

当我想要每个文件有以下内容(四行合一)时

connect <changing value> , <changing value> #0x <changing value> , <changing value> #0x <changing value> , <changing value> #0x <changing value> , <changing value> #0x <changing value>

相关内容