Blank lines 
Author Message
 Blank lines

Sorry if this question is way too basic, but..........

If i have a file in which i want to print ONLY the lines between 2 blank
lines, why can i not set a pattern as such:

/    /,/     /

In other words, how do i represent:

 / blank_line /, / blank_line /

I have tried various ways to do this:

/'    '/,/'    '/
/"  "/,/"    "/
/ \n /,/ \n /
/ (length == 0) /,/ (length == 0) /

(Some of which are probably really dumb, i know)

Does anyone know of a way i can achieve this????

Cheers in advance,
Alex...



Wed, 04 Aug 2004 02:55:04 GMT  
 Blank lines

Quote:

> Sorry if this question is way too basic, but..........

> If i have a file in which i want to print ONLY the lines between 2 blank
> lines, why can i not set a pattern as such:

> /    /,/     /

> In other words, how do i represent:

>  / blank_line /, / blank_line /

> I have tried various ways to do this:

> /'    '/,/'    '/
> /"  "/,/"    "/
> / \n /,/ \n /
> / (length == 0) /,/ (length == 0) /

> (Some of which are probably really dumb, i know)

> Does anyone know of a way i can achieve this????

> Cheers in advance,
> Alex...

Here is one solution :
 awk -v RS="" 'NR==2' yourfile

If you need to print more than one such pattern, replace
NR==2 with (NR%2)==0

HTH

--
roland



Wed, 04 Aug 2004 05:19:42 GMT  
 Blank lines

Quote:
> Sorry if this question is way too basic, but..........

> If i have a file in which i want to print ONLY the lines between 2
blank
> lines, why can i not set a pattern as such:

> /    /,/     /

> In other words, how do i represent:

>  / blank_line /, / blank_line /

> I have tried various ways to do this:

> /'    '/,/'    '/
> /"  "/,/"    "/
> / \n /,/ \n /
> / (length == 0) /,/ (length == 0) /

> (Some of which are probably really dumb, i know)

> Does anyone know of a way i can achieve this????

The problem here is that in awk a range match checks the current line
against the pattern that starts the range and against the pattern that
ends the range, unlike sed, which starts checking for the pattern that
matches the end of the range from the next line.  So any code like

    / /,/ / { .... }

where the start and end patterns are effectively the same will switch on
the rule and then turn it off again at the same point ;-(

You therefore become involved in "kludges" to work around this, or,
sometimes much easier, use sed.

HTH
--
Peter S Tillier
"Who needs perl when you can write dc in sed?"
peter dot tillier at btinternet dot com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Wed, 04 Aug 2004 06:21:50 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. remove blank lines before lines beginning with string

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

3. inserting a blank line in a file

4. to insert a blank line

5. adding blank lines to text file

6. print contents up to blank line

7. datafile has blank lines

8. Removing data between blank lines

9. blank lines

10. how to specify a blank line as record separator

11. Blank lines problems

12. Using gawk to replace blank lines

 

 
Powered by phpBB® Forum Software