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("%g",sum)
else
printf("--"
printf(i < nfld ? "\t" : "\n"
}
}
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++)
numcol=isnum($i)
}
{ for (i=1; i <=NF; i ++)
if (numcol)
sum += $i
}
END { for (i=1; i <=nfld; i++) {
if (numcol)
printf("%g",sum)
else
printf("--"
printf(i < nfld ? "\t" : "\n"
}
}
function isnum { return n ~ /^[+-]?[0-9]+$/ }