LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-01-2010, 08:09 AM   #1
xfrantzis
LQ Newbie
 
Registered: Jul 2010
Posts: 1

Rep: Reputation: 0
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
 
Old 07-01-2010, 10:06 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove some blocks from a sparse file hpsmouse Programming 10 08-16-2009 09:32 AM
Remove specific text in output line dwarf007 Linux - General 8 07-04-2007 12:28 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 05:32 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 08:15 PM
Script file to replace large text blocks in files? stodge Linux - Software 0 09-27-2003 11:53 AM


All times are GMT -5. The time now is 11:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration