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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Validation with Awk (Aho, Kernighan, Weinberger p.77)

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++)
type = isnum(i$)
}{if (NF !=nfld)
printf(&quot;line %d has %d fields instead of %d\n&quot;,
NR, NF, nfld)
for (i=1, i<=NF; i++)
if (isnum($i) !=type)
printf(&quot;field %d in line %d differs from line 1\n&quot;,
i,NR)
}

function isnum(n) {return n ~ /^[+-]?[0-9]+$/ }
 

The [ i ] in your post has turned on italics. Repost with process TGML unchecked. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top