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*

7
  • Does it need to be data[$1]=1; next? Wouldn't just data[$1]; next be sufficient? Commented Mar 9, 2020 at 13:09
  • @guest Possibly, if you're tired of typing, yes. I think that should work, but as I'm not 100% certain it works everywhere I opted for setting a value. Commented Mar 9, 2020 at 13:12
  • I'm sorry sir, i think my question is a bit wrong, should i change the main post? file A.txt and B.txt content does not have the same line number, and means a.txt record may be in random position. i tried your solution but it did'nt work, apparently FNR==NR compare if the record is on the same line am i right? any ways thanks Commented Mar 9, 2020 at 13:16
  • 1
    Thanks so much sir with detailed explanation as well, i tried doing many days already by searching around the forum, but still can't make it the way i want, and yours only using one line :D Guess i did learn something here and there, glad i ask a question here, it solved instantly.. Commented Mar 9, 2020 at 13:46
  • 1
    @guest - yes, data[$1]; next is all you need and will work in any awk. Using data[$1]=1 may just take up more memory, depending on how the arrays are implemented. Commented Mar 10, 2020 at 18:49