![处理多个文件,提取多个匹配项并打印(保存)到文件](https://linux22.com/image/122359/%E5%A4%84%E7%90%86%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%EF%BC%8C%E6%8F%90%E5%8F%96%E5%A4%9A%E4%B8%AA%E5%8C%B9%E9%85%8D%E9%A1%B9%E5%B9%B6%E6%89%93%E5%8D%B0%EF%BC%88%E4%BF%9D%E5%AD%98%EF%BC%89%E5%88%B0%E6%96%87%E4%BB%B6.png)
我正在尝试解析多个文件以创建摘要报告。每个文件包含多行感兴趣的行,我想将它们组合成一行。每个文件都包含我匹配的以下数据集:
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>