I am attempting to parse many log files using bash. The log files look something like this:
"",1/8/2016
"Timezone",-6
"Serial No.","000001"
"Location:","LS_trap_2c"
"High temperature limit (�C)",-20
"Low temperature limit (�C)",-40
"Date - Time","Temperature (�C)"
"8/11/2015 12:00",28.0
"8/11/2015 14:00",28.5
"8/11/2015 16:00",24.0
"",1/8/2016
"Timezone",-6
"Serial No.","000002"
"Location:","LS_trap_2D"
"High temperature limit (�C)",-20
"Low temperature limit (�C)",-40
"Date - Time","Temperature (�C)"
"8/11/2015 12:00",28.0
"8/11/2015 14:00",28.5
I want to append the Serial no., and Location (and maybe others later on) onto each line until the next header is reached, and output this to a master.csv file. The file should look like this ultimately:
"",1/8/2016
"Timezone",-6
"Serial No.","000001"
"Location:","Trap_2c"
"High temperature limit (�C)",-20
"Low temperature limit (�C)",-40
"Date - Time","Temperature (�C)"
LS_trap_2c,000001,"8/11/2015 12:00",28.0
LS_trap_2c,000001,"8/11/2015 14:00",28.5
LS_trap_2c,000001,"8/11/2015 16:00",24.0
"",1/8/2016
"Timezone",-6
"Serial No.","00002"
"Location:","LS_trap_2D"
"High temperature limit (�C)",-20
"Low temperature limit (�C)",-40
"Date - Time","Temperature (�C)"
LS_trap_2D,00002,"8/11/2015 12:00",28.0
LS_trap_2D,00002,"8/11/2015 14:00",28.5
Here is a question that helped me do processing on similar files using bash sed:
Bash Append header information to each line of a file until next header found
This oneliner is great for finding a header, storing it in holdspace and adding it into the front of each line
sed -r '/^"/h;//!{G;s/(.*)\n.*"(.*)"/\2,\1/}' fil.csv >masfil.csv
This approach has not worked for appending multiple strings to the front since I am unsure of how to use multiple hold spaces with sed. Also, I'm not sure if sed is the best way to do this. I'm not very familiar with sed so any pointers would be greatly appreciated.