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!

Re-post of Awk Data Processing Question

Status
Not open for further replies.

AwkRookie

Programmer
Oct 15, 2002
10
US
Trying to run the script in Section 3.2, page 77 of 'Data Validation' in the Aho, Kernighan, Weinberger book. I have a set of data that is 8-column numeric as input that will read in without any errors but I get no output. What is the problem? Should the code below run without error and if it doesn't, is there a problem with my data formatting?

Also, if I want to read in numeric data that is in HH:MM:SS, i.e., time-based data, how do I handle the colons since the rest of the data is tab delimited? can this be treated as a single field or must it be divided into multiple fields?

Example from book is:

NR==1 { nfld = NF
for (i=1; i<=NF; i++)
numcol=isnum($i)
}
{ for (i=1; i <=NF; i ++)
if (numcol)
sum += $i
}
END { for (i=1; i <=nfld; i++) {
if (numcol)
printf(&quot;%g&quot;,sum)
else
printf(&quot;--&quot;)
printf(i < nfld ? &quot;\t&quot; : &quot;\n&quot;)
}
}
function isnum(n) { return n ~ /^[+-]?[0-9]+$/ }
 
Hi AwkRookie,

I think your code sample isn't displaying quite right. This is because '' in the code that got interpreted as a TGML instruction instead of as an array subscript.

You might want to unclick the 'Process TGML' checkbox just below the Reply editor.

When you resend your code, you probably should send some sample data as well.

Grant.
 
Hi AwkRookie,

Ha! I'm such a dope. I just repeated the mistake I was telling you about.

My message SHOULD have read:

I think your code sample isn't displaying quite right. This is because '' in the code that got interpreted as a TGML instruction instead of as an array subscript.

You might want to unclick the 'Process TGML' checkbox just below the Reply editor.

When you resend your code, you probably should send some sample data as well.

Grant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top