Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Flush problem
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 2162 of 2234
Post > Topic >>

Flush problem

by Prateek <prateek.a@[EMAIL PROTECTED] > Feb 12, 2008 at 02:39 PM

Hi,
My question is having two parts:

1. I am having this script:

BEGIN {FS="|"}
{
gsub(/.*/,"\"&\"",$6);
ORS=",";
for(i=1;i<NF;i++){print $i;}
ORS="\n";
#print "";

}

In the above script, I am double qouting my sixth field and then
trying to print all the fields separated by comma. Each record should
be printed on a new line.

But when I do the above, my ORS="\n" does not take into effect as the
entire file (all records) are printed comma separated and not on new
line as desired.

So I tried introducing print stmt which is the last commented stmt in
above script. It does the work i.e the output is as :

10405349,01/03/08 21:29:03,01/09/08 02:01:21,Closed,AUTO
EVENT,"CENTRAL TWS_JOB_ABEND JOB JMKTIS_3TPEMGR00M_ARCHIVE_CASES
FAILED, STREAM SMKTIS_TPEMGR03G, NO RECOVERY SPECIFIED",P3,
10416266,01/06/08 21:13:00,01/10/08 08:03:46,Closed,AUTO
EVENT,"CENTRAL TWS_JOB_ABEND JOB JMKTIS_3TPEMGR00M_ARCHIVE_CASES
FAILED, STREAM SMKTIS_TPEMGR03G, NO RECOVERY SPECIFIED",P3,

So as seen above, record is getting printed on a new line but the
previous record is ending with a comma which is not desired after P3.

So my question to you all is does OFS take effect only after one print
stmt which effectively flushes the buffer. Is this a bug or am I
missing something?


2. Also when I redirect the same to a file by

BEGIN {FS="|"}
{
gsub(/.*/,"\"&\"",$6);
ORS=",";
for(i=1;i<NF;i++){print $i >> FILENAME"_formatted";}
ORS="\n";
print "";
}

the entire output is only comma separeted and no new line (which was
atleast the case when directing to screen)



Looking fwd to your replies.

Thanks,
Prateek




 1 Posts in Topic:
Flush problem
Prateek <prateek.a@[EM  2008-02-12 14:39:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun May 11 17:02:48 CDT 2008.