wc -L giving incorrect length of longest line

Running below line gives 3957 as length of longest line in file 20121119_SRMNotes_init.dat

awk ' { if ( length > 3950 ) { x = length } }END{ print x }' 20121119_SRMNotes_init.dat

While wc -L 20121119_SRMNotes_init.dat gives output as 4329. Why is there a difference between these two commands.

Thanks

Your awk command will give you only the length of last line greater than 3950, try this instead:-

awk '{ if (x < length()) x = length() } END { print x } ' 20121119_SRMNotes_init.dat

also:

awk 'length>x {x=length} END {print x}' 20121119_SRMNotes_init.dat