Removing data between blank lines 
Author Message
 Removing data between blank lines

Hi everyone,

I have an input file that looks something like:

Element
Match

Line1
Line2

Line3
Line4

Match

Line1
Line2

Line3
line4

Match

Line1
Line2

Element
Match

Repeat as above

What I'd like to do is retain every Element/Match and the lines that follow
until the line before the next Match. Thereafter, the block of data between the
line starting with Match and the line before the next Element/Match lines I'd
like to delete.

So far, I thought the 'script' could be:

1.  Look for empty lines /^%$/
2.  If the next line starts with /^Match/
3.  Make empty all lines until the line before the line that starts with
/^Element/.

.... or variations thereof ...

So far, using my rudimentary scripting skills, I've written lots (really!) of
scripts that actually run ... but just not giving me the output I want :-(

Any help would be greatly appreciated.

Cheers,

Giovanni

--
Posted from wwwproxy.scu.edu.au [203.2.32.27]
via Mailgate.ORG Server - http://www.*-*-*.com/



Tue, 04 May 2004 06:50:02 GMT  
 Removing data between blank lines

Quote:

> What I'd like to do is retain every Element/Match and the lines that follow
> until the line before the next Match. Thereafter, the block of data between the
> line starting with Match and the line before the next Element/Match lines I'd
> like to delete.

I'm not quite sure I understand what you mean. If there's always a
Match after each Element and you want to print only lines from that
point up to but not including the next Match, this should do it:

/^Element/ {
  print; getline
  do { print } while (getline && $0 !~ /^Match/)

Quote:
}

That assumes there's always at least one extra Match after
each Element. If that's not the case, i.e., sometimes there's
just one Match between Element lines, try this:

{ while (/^Element/) {
    print; getline
    do { print } while (getline && $0 !~ /^(Match|Element)/)
  }

Quote:
}
> So far, I thought the 'script' could be:

> 1.  Look for empty lines /^%$/
> 2.  If the next line starts with /^Match/
> 3.  Make empty all lines until the line before the line that starts with
> /^Element/.

That doesn't match your description above.  Do you wish to delete the
lines or make them empty?  Do you wish to keep any Match lines after
Element if they're not preceded by a blank line?  Do you wish to
delete the blank line preceding a Match that's deleted?
What should happen if there's something in the file before first Element?

--
Tapani Tarvainen



Tue, 04 May 2004 15:06:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. remove blank lines before lines beginning with string

2. blank lines/lines with spaces (how to remove)

3. Want to remove multiple occurances of blank line from a file

4. remove blank lines

5. Text Widget: removing blank lines

6. Sorting multiple-line data to single line data

7. Removing trailing blanks

8. Remove Leading Blanks

9. Removing multiple blanks

10. challenge: remove blanks subroutine

11. how to remove trailing blanks of a string?

12. removing blanks from a file

 

 
Powered by phpBB® Forum Software