0

I’m trying to parse multiple files to create a summary report. Each file contains multiple lines of interest which I want to combine into a single line. Each file contains the following data set that I am matching on:

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

My crude command line is as follows

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

but this only combines four matches for each file in the format which leads to

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>

when I want the following (four lines into one) for each file

connect <changing value> , <changing value> #0x <changing value> , <changing value> #0x <changing value> , <changing value> #0x <changing value> , <changing value> #0x <changing value>
  • can you extend your input for at least 2-3 files? – RomanPerekhrest Nov 23 '17 at 22:15
  • Do you guarantee that each file will have exactly one connect line and four #0x lines (in that order)?  If not, is there any data pattern that always appears after the last #0x line (but not before)? – G-Man Nov 23 '17 at 23:20
  • The output from the grep will be in that format, connect and four #0X then the next file and so on – deepsix86 Nov 25 '17 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.