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("line %d has %d fields instead of %d\n",
NR, NF, nfld)
for (i=1, i<=NF; i++)
if (isnum($i) !=type)
printf("field %d in line %d differs from line 1\n",
i,NR)
}
function isnum
{return n ~ /^[+-]?[0-9]+$/ }
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("line %d has %d fields instead of %d\n",
NR, NF, nfld)
for (i=1, i<=NF; i++)
if (isnum($i) !=type)
printf("field %d in line %d differs from line 1\n",
i,NR)
}
function isnum