Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • You could probably use rows == "" || FNR <= rows as the first condition, or remove it completely. I'm assuming that the ROWS variable in their code is a byproduct of their way of thinking about the problem rather than a necessary part of the solution. Commented May 3, 2022 at 5:52
  • @Kusalananda Yes I've removed it. The script should have set ROWS=$(wc -l) or something. Commented May 3, 2022 at 5:53
  • 1
    @algae Since all the fields on each line have to be summed with the corresponding elements in the other files, you can't really print each line as you go, as the sum would not be "done" yet. Also, the amount of memory taken should be no more than the amount needed to store one of the files in RAM. Commented May 3, 2022 at 6:14
  • 2
    @algae FNR is the line number in the current file. The fields of that line has to be added to the corresponding entries in each of the other files. When FNR increments, that just means you have started working on the next line from the same file. Commented May 3, 2022 at 6:21
  • 1
    @algae I added an alternative that should use much less memory Commented May 3, 2022 at 8:12