how to handle multiline fields and records? 
Author Message
 how to handle multiline fields and records?

I am trying to process a text file having multiline fields
and also, it contains a record separator stuck in.

like,

firstname|^a^b^c|lastname|^a^b^c^|phone|^a^b^c||^x^y^z|firs
tname|^a^b^c|lastname|^a^b^c||^a^b^c|

in the above line, |^a^b^c| is the field separator, and
                   |^x^y^z| is the record separator.

How do I come up with construct to process this in awk.

thanks in advance.

p.s. It might happen that one of fields may span more than
one line.



Thu, 11 Mar 1999 03:00:00 GMT  
 how to handle multiline fields and records?

: I am trying to process a text file having multiline fields
: and also, it contains a record separator stuck in.

: like,

:  
: firstname|^a^b^c|lastname|^a^b^c^|phone|^a^b^c||^x^y^z|firs
: tname|^a^b^c|lastname|^a^b^c||^a^b^c|

: in the above line, |^a^b^c| is the field separator, and
:                    |^x^y^z| is the record separator.

: How do I come up with construct to process this in awk.

: thanks in advance.

: p.s. It might happen that one of fields may span more than
: one line.

The new line is always a field separator in AWK, so you
have to split the lines manually. Here is a skeleton for you.
---
BEGIN {yourRS="as you like it"; yourFS="this too";}

{  while(match(yourRS,$0)) {
      yourRecord = yourRecord substr($0,1,RSTART-1);
      $0 = substr($0,RSTART+RLENGTH);
      process(yourRecord);
      yourRecord="";
      }
   yourRecord = $0;

Quote:
}

END {process(yourRecord);}

function process(r) {
   yourNF = split(r,a,yourFS);
   # your fields are a[1], ..., a[yourNF]
   # Do what you like.
   # However, don't change $0 !

Quote:
}

---
A line may begin with yourRS, then you process yourRecord
as is (nothing concatenated with it).
Indeed, parts of yourRS may fall in different lines.
Or a little bit different main action on another

Hope this helps,
Toth Andras



Fri, 12 Mar 1999 03:00:00 GMT  
 how to handle multiline fields and records?

: : I am trying to process a text file having multiline fields
: : and also, it contains a record separator stuck in.

: : like,

: :  
: : firstname|^a^b^c|lastname|^a^b^c^|phone|^a^b^c||^x^y^z|firs
: : tname|^a^b^c|lastname|^a^b^c||^a^b^c|

: : in the above line, |^a^b^c| is the field separator, and
: :                    |^x^y^z| is the record separator.

: : How do I come up with construct to process this in awk.

: : thanks in advance.

: : p.s. It might happen that one of fields may span more than
: : one line.

: The new line is always a field separator in AWK, so you
: have to split the lines manually. Here is a skeleton for you.
: ---
: BEGIN {yourRS="as you like it"; yourFS="this too";}

: {  while(match(yourRS,$0)) {
:       yourRecord = yourRecord substr($0,1,RSTART-1);
:       $0 = substr($0,RSTART+RLENGTH);
:       process(yourRecord);
:       yourRecord="";
:       }
:    yourRecord = $0;
: }

: END {process(yourRecord);}

: function process(r) {
:    yourNF = split(r,a,yourFS);
:    # your fields are a[1], ..., a[yourNF]
:    # Do what you like.
:    # However, don't change $0 !
: }
: ---
: A line may begin with yourRS, then you process yourRecord
: as is (nothing concatenated with it).
: Indeed, parts of yourRS may fall in different lines.
: Or a little bit different main action on another

I'm following up to this followup since I never saw the original post...

I'm not sure if this solution will work or not... but since the records
aren't fixed length, and since the newlines don't seem to be a part of
them, why not just do two passes... clober the \n's with your favorite
technique, and then handle the result using gawk 3's regexp FS/RS?

andru



Fri, 12 Mar 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Best way to handle variable length fields within records

2. multiline records

3. Variable multiline record averaging

4. moving multiline records into one line each

5. Help combining multiline records

6. Multiline record - how to detect?

7. Multiline Record Gawk extraction problem

8. awk w/ multiline records

9. Multiline entry fields in VisPro/REXX 3.X gold

10. Prime record fields on insert - Before adding auto incremented record

11. Color a record in a browse list box by condition of the field in that record

12. Ascii-records (with some comp fields) to plain Ascii-records

 

 
Powered by phpBB® Forum Software