awk/nawk returning decimal values?
Hi
Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. I tried to pass the OTMF variable in the nawk statement to "%.8d" but nothing helped. Any awk/nawk expert woudl be able to figure this out? Thanks for your help guys |
Maybe it is a typo, but the variable is OFMT. According to the AWK manual:
Quote:
|
thanks for the reply colucix
i actually meant OFMT i tried your suggestion as follows: /bin/nawk -F'|' '{OFMT="%.0f"; printf $1;printf "|"; printf $1;printf "|"; printf $2;printf "|"; printf $3;printf "|"; printf $3;printf "|"; printf $4;printf.......... I still get the float type value returned not the integer... Any other idea? Thanks for this |
Tried gawk?
Code:
echo "" |awk '{printf"%d\n", 12595594224142}' Code:
awk -F'|' '{printf "%d | %s | %s | %s | %s | %s |\n", NR, $1, $2, $3, $4, $5}' file Cheers, Tink |
Two notes: 1. the variable OFMT controls the output of the print statement, which internally uses the C function sprintf to convert numbers to strings. If you use the printf statement, you can specify the format as in
Code:
printf "%.0f",$1 # or simply Code:
print $1 Code:
print $1+0 |
thanks for the help on this guys
i might not have been clear but i'm not trying to convert float values or fields within the file to decimal. i'm trying to convert the actual line number output of the incriminated line reported by default by awk as a float if it exceeds 6 digits. hence i'm actually not sure if OMFT can actually help as coculix outlined... any other ideas? |
Did you see my gawk example above? That's like outputting a line-number.
Maybe you've found an nawk limitation? Actually I just checked: nawk will print those long integers just fine using printf "%d" Cheers, Tink |
All times are GMT -5. The time now is 09:48 AM. |