[LINUX] I used gawk to find out the maximum value that goes into NF.

Trigger

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

Survey (document)

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.

Survey (Guguru)

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

So how far is the maximum?

There was a page that could be a hint.

https://kumikomiya.com/mastering-float/

If you feel like it, do a little more research.

Postscript (2020/08/04)

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

I used gawk to find out the maximum value that goes into NF.
I used Python to find out about the role choices of the 51 "Yachts" in the world.
I measured 6 methods to get the index of the maximum value (minimum value) of the list
I tried to summarize the operations that are likely to be used with numpy-stl
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to find out how to streamline the work flow with Excel x Python ①
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to put pytest into the actual battle
I felt that I ported the Python code to C ++ 98.
Extract the maximum value with pandas and change that value
I want to find a stock that will rise 5 minutes after the Nikkei Stock Average rises
I dare to fill out the form without using selenium
I tried to find the entropy of the image with python
I want to initialize if the value is empty (python)
I tried to find the average of the sequence with TensorFlow
Inherit the standard library to find the average value of Queue
Find the index of the maximum value (minimum value) of a multidimensional array
I tried to summarize the code often used in Pandas
I tried to summarize the commands often used in business
I tried to divide the file into folders with Python
I tried to find out how to streamline the work flow with Excel × Python, my article summary ★
I tried to find out in which language that software that I always take care of is written
I tried to expand the database so that it can be used with PES analysis software
I made an app to find out who the members of the Straw Hat Pirates look like
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
I tried to find out as much as possible about the GIL that you should know if you are doing parallel processing with Python