LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to remove specific text blocks in a file (http://www.linuxquestions.org/questions/linux-software-2/how-to-remove-specific-text-blocks-in-a-file-817381/)

xfrantzis 07-01-2010 07:09 AM

How to remove specific text blocks in a file
 
Hello everyone,
I have a text file (actually a log file from a sensor) that looks like this:

Date/Time: 10.07.01 11:03:59
00 Battery Voltage 13.5 Volt
01 Reference 71
02 Wind speed 6.68 m/s
03 Wind gust 9.3 m/s
04 Wind direction 315.38 Deg.M
05 Air temperature 25.20 Deg.C
06 Relative humidity 66.11 % RH
07 Air pressure (QNH) 997.56 hPa
08 Net atm. radiation 1074.5 W/sqm

Date/Time: 10.07.01 11:04:59
00 Battery Voltage 13.5 Volt
01 Reference 71
02 Wind speed 6.68 m/s
03 Wind gust 9.6 m/s
04 Wind direction 310.11 Deg.M
05 Air temperature 25.20 Deg.C
06 Relative humidity 66.51 % RH
07 Air pressure (QNH) 997.75 hPa
08 Net atm. radiation 1070.2 W/sqm

Date/Time: 10.07.01 11:05:59
00 Battery Voltage 13.5 Volt
01 Reference 71
02 Wind speed 5.59 m/s
03 Wind gust 7.7 m/s
04 Wind direction 307.65 Deg.M
05 Air temperature 25.29 Deg.C
06 Relative humidity 65.30 % RH
07 Air pressure (QNH) 997.56 hPa
08 Net atm. radiation 1074.5 W/sqm


I want to delete every block that is not complete. If any of the above lines (Date line or lines 00 to 08)is missing I want to completely remove the block.
thanks

pixellany 07-01-2010 09:06 AM

Welcome to LQ!!

What programming languages are you familiar with?

One way to do this would be to simply accumulate the records into a buffer, while checking to see that each line is there. As soon as a missing line is found, break out of that loop and go to the next record. If all the lines ARE there, then print the contents of the buffer.

Example:
Code:

set up main loop to look for lines beginning with "Date/Time".
    If found, loop thru following lines looking for 00 thru 08
        Add lines to buffer
        If line missing, break out into main loop
        All lines found
              print buffer
              break our into main loop
    end inner loop
end main loop



All times are GMT -5. The time now is 07:18 AM.