how to specify a blank line as record separator 
Author Message
 how to specify a blank line as record separator

Working with multiline records , using RS="" and FS="\n"
problem occurs when there is blank line having a space character in
between, in that case space is treated as a valid field.
How do I specify any blank line as a record separator ?
Using HP-UX 10.2 standard awk.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 15 Dec 2002 03:00:00 GMT  
 how to specify a blank line as record separator

Quote:

>Working with multiline records , using RS="" and FS="\n"
>problem occurs when there is blank line having a space character in
>between, in that case space is treated as a valid field.
>How do I specify any blank line as a record separator ?
>Using HP-UX 10.2 standard awk.

I would suggest that you simply change all of those lines with only
spaces to blank lines first, probably using sed, and then process
it by piping the result to your awk stuff.  Something like this:

sed 's/^[ ]*$//' infile | awk ...

Note that if you want to change lines with only spaces _AND tabs to
blank lines, include a tab as well as a space inside the brackets.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 15 Dec 2002 03:00:00 GMT  
 how to specify a blank line as record separator

Quote:


>>Working with multiline records , using RS="" and FS="\n"
>>problem occurs when there is blank line having a space character in
>>between, in that case space is treated as a valid field.
>>How do I specify any blank line as a record separator ?
>>Using HP-UX 10.2 standard awk.

>I would suggest that you simply change all of those lines with only
>spaces to blank lines first, probably using sed, and then process
>it by piping the result to your awk stuff.  Something like this:

>sed 's/^[ ]*$//' infile | awk ...

>Note that if you want to change lines with only spaces _AND tabs to
>blank lines, include a tab as well as a space inside the brackets.

Just to make Kenny happy, ... :-)

You could do the sed preprocessing thing with awk like this:

awk '/^[ ]*$/{$0=""}{print}' | awk ...

The same advice about tabs applies.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 15 Dec 2002 03:00:00 GMT  
 how to specify a blank line as record separator

...

Quote:
>Just to make Kenny happy, ... :-)

A worthwhile goal, to be sure.

Quote:
>You could do the sed preprocessing thing with awk like this:

>awk '/^[ ]*$/{$0=""}{print}' | awk ...

>The same advice about tabs applies.

Or, you could do what I would suggest (and which I almost posted the first
time I saw this thread), which is to dispense with the RS/FS stuff altogether
(I generally recommend against mucking with these[*]), and do this:

!NF { p();next }
{ s = s $0 "\n" }
END     { p() }
function p() {
        if (!s) return
        # process s here
        s = ""
        }

Alternatively, instead of building up the string s, you could build up an
array (this maps to the OP's use of FS="\n"), by changing the second line to:

{ arr[++n] = $0 }

and, of course, making the other changes to support this (and setting n to 0).

[*]  I did recently write a program that processes C programs, with RS=ORS=";"



Sun, 15 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Specifying multiple field separators

2. remove blank lines before lines beginning with string

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

4. records span multiple lines; Record Separator is row of asterisks

5. Need help on record separator

6. Impossible Record Separator

7. Bracked-R Active File Record Separator

8. is there a record separator? RS

9. Perl-style input record separator in Python?

10. tclX: scancontext: Can I change the record separator?

11. multiple lines matching without separator

12. line separators in file-output

 

 
Powered by phpBB® Forum Software