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*

12
  • BTW, this awk script is run once and processes both files in one pass. this is as fast as it gets. Your while-read-awk loop runs awk once for every line in in.txt, this is about as slow as it gets - partly because of the overhead of starting up awk and partly because reading text in a shell while loop is slow. Commented Oct 24, 2021 at 6:59
  • 1
    I gave up on NR==FNR after one of my clients passed an empty first file, and my awk tried to build a 40GB array from the second file. I moved to awk 'myAwk' fSeq=1 A.file fSeq=2 B.file. This also works for multiple reference files. Commented Oct 24, 2021 at 8:15
  • @Paul_Pedant GIGO. BTW, technically an empty file isn't a text file - it doesn't have a line ending in \n Commented Oct 24, 2021 at 10:23
  • @cas thanks,,,so technically it will consume less cpu right...i compare both side by side awk consumes high cpu... Commented Oct 24, 2021 at 14:47
  • 2
    @UncleBilly that statement is so unjustifiably smug and arrogant that I don't even think it's possible for a human. How about using your god-like genius to correct the literally hundreds of answers here on this site that use FNR==NR? What's lame is that awk doesn't deal with it sanely - it should treat an empty file as if it had one line, even if it doesn't have a newline. Either that, or it should have a file-counter variable, perhaps FC, that can be used instead. Commented Oct 25, 2021 at 0:28