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!

Re-post (of Re-post) of Awk question Aho p. 77

Status
Not open for further replies.

AwkRookie

Programmer
Oct 15, 2002
10
US
Glanced over & saw "check" instead of "uncheck" - sorry.

I am using all-numeric data, tab-delimited, as input to the following code from top of p.77; is there any reason that this script should not run as typed?:

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 program runs, here is the OP:

line 2 has 4 fields instead of 3
field 3 in line 2 differs from line 1
line 3 has 4 fields instead of 3
field 2 in line 3 differs from line 1
field 3 in line 3 differs from line 1
line 5 has 4 fields instead of 3
field 3 in line 5 differs from line 1
line 6 has 4 fields instead of 3
field 2 in line 6 differs from line 1
field 3 in line 6 differs from line 1

You need to change the dollar sign on line 6:
$d to %d.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top