Back to front pageView on Hacker News (opens in a new tab)Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years agoPreferably an elegant snippet rather than an entire (well engineered) codebase.Comments (380) 116 threadsShow all commentsShowing thread 114 of 116[-]known7 years ago1 reply#awk '!seen[$0]++'awk 'NR==FNR{A[$0]; next} $0 in A' file1.txt file2.txtflukus7 years ago#Thanks, was trying to remember that first trick just last week. For log files I had to make a slight adjustment to filter the time at the front: !seen[gensub($1, "", "g", $0)]++ For anyone wondering, it filters out duplicates by storing the first occurrence of the line and skipping subsequent ones.
Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years ago
flukus7 years ago#Thanks, was trying to remember that first trick just last week. For log files I had to make a slight adjustment to filter the time at the front: !seen[gensub($1, "", "g", $0)]++ For anyone wondering, it filters out duplicates by storing the first occurrence of the line and skipping subsequent ones.
Comments (380) 116 threads
Show all comments
Showing thread 114 of 116
awk 'NR==FNR{A[$0]; next} $0 in A' file1.txt file2.txt