Previously, the following files
sample.txt
1 2 3 4 5 6 7 8 9
There are times when you want to insert line breaks by 3 digits as shown below.
1 2 3
4 5 6
7 8 9
I wrote the following awk script.
{
for(i=1; i<=NF; i++) {
printf "%d ", $i;
if((i % 3) == 0) print "";
}
}
I wondered, "How many input files can this support?" I wonder if such a file is okay. .. ..
sample.txt
1 2 3 4 5 6 7 8 9 ... /*This is followed by a large number of numbers*/ .... 9999999999999999999
Something may be written in the NF description of the document.
https://www.gnu.org/software/gawk/manual/gawk.html#index-NF-variable
NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a record. No matter how many fields there are, the last field in a record can be represented by $NF. So, $NF is the same as $7, which is ‘example.’. If you try to reference a field beyond the last one (such as $8 when the record has only seven fields), you get the empty string. (If used in a numeric operation, you get zero.)
I expected a description like "The maximum value that can be entered in NF ...", but nothing in particular.
Here is the description you care about.
https://stackoverflow.com/questions/8857866/printing-long-integers-in-awk#comment11152277_8858003
Correct. According to info gawk: "The internal representation of all numbers, including integers, uses double-precision floating-point numbers. On most modern systems, these are in IEEE 754 standard format."
Certainly, there is a description in the document.
https://www.gnu.org/software/gawk/manual/html_node/Scalar-Constants.html#DOCF30
There was a page that could be a hint.
https://kumikomiya.com/mastering-float/
If you feel like it, do a little more research.
Comments were received at Occasionally miscellaneous notes Re * .. Thank you very much.
Actually, the manual The GNU Awk User's Guide clearly states the restrictions in this area (until version 5, it is described in the file called LIMITATIONS in the source archive, not in the manual).
It's true. (I didn't notice: sweat :) https://www.gnu.org/software/gawk/manual/gawk.html#Implementation-Limitations
Recommended Posts