我正在嘗試解析多個文件以建立摘要報告。每個文件包含多行感興趣的行,我想將它們組合成一行。每個文件都包含我匹配的以下數據集:
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>