Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem joining lines in awk

Status
Not open for further replies.

ahuva

Programmer
Feb 1, 2001
1
US
Hi ,

I have a question. If you can help me I would really appreciate it.

I am attaching a file containing a few records. I am trying to load them
into a table. However some records have a "return" (enter) in middle of
the record which splits the record into 2 or 3.
the fields are divides with bars ("|"). Every line has to have 57 bars.
How do I say in awk that if a line does not have 57 bars it should join
it with the next line?

Please let me know of any solutions.

Thanks
Ahuva
/**This file contains 2 records. (each starting with 37.... The problem is that the first record is divided into 3**/


379331198|MPTPLUS|Pollard, John and Bonnie|||John Pollard and Bonnie Pollard||John Pollard and Bonnie Pollard|721 Maple Ridge Road||Milford|OH|45150|US|||285-26-7575|CASH||9/30/1999 0:00:00|A|1|6/30/1999 0:00:00|Q|1|Q|0||1|Mr. and Mrs. Pollard||O|||||||||||||0|||1|0|0||1|1|V||0.00||RCA 379331201|MPT|Juniet, Mary|Moderate||Mary Juniet||Mary Juniet|9830 Regatta Drive #101||Cincinnati|OH|45252|US|||289-57-6056|CASH||9/30/1999 0:00:00|A|1|12/31/1999 0:00:00|Q|1|Q|0|10/11/99 assets to be transferred out.
12/14/99 - per Chris Kiley - client decided she wanted this account under management. 3-31-00 Per Chris Kiley, account should be closed.|1|Ms. Juniet||C||||||||4/13/2000 0:00:00|ADMIN|1.58|3/31/2000 0:00:00||0|||1|0|0||1|1|V||0.00||
379330671|MPTPLUS|Cox, James|||James Cox|Rollover IRA|James Cox|10216 Dewhill||Cincinnati|OH|45251|US|||271-36-2689|CASH||9/30/1999 0:00:00|A|1|6/30/1999 0:00:00|Q|1|Q|0||1|Mr. Cox||O|||||||||||||0|||1|0|0||1|1|V||0.00||RCA
 
Ahuva-

This should do what you need.


#! /bin/sh

nawk 'BEGIN{FS=""}

{
count += gsub(/\|/,"\|")

if ( count < 57 ) {
printf (&quot;%s&quot;, $0)
next
}

if (count == 57 ) {
printf(&quot;%s\n&quot;, $0)
}

count =0

}' $1 > $2

Hope this helps!


flogrr
flogr@yahoo.com

 
ahuva,

AWK/NAWK provides you with NF (Number of Fields) that could be used as an alternative to count.

Rich
 
riichman-

ahuva needed to count &quot;pipes&quot; not fields in order
to break out multiple lines into records.



flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top