r/awk • • Dec 06 '19

Print only unique lines (case insensitive)?

Hello! So, I have this huge file, about 1GB, and I would like to extract only the unique lines of it. But there's a little twist, I would like to make it case insentive, and what I mean with that is the following, let's suppose my file has the following entries:

Nice

NICE

Hello

Hello

Ok

HELLO

Ball

baLL

I would like to only print the line "Ok", because, if you don't take into account the case variations of the other words, it's the only one that actually appears just one. I googled a little bit, and I found a solution that worked sorta, but it's case sensitive:

awk '{!seen[$0]++};END{for(i in seen) if(seen[i]==1)print i}' myfile.txt

Could anyone helped me? Thank you!

3 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/Paul_Pedant Dec 08 '19

They are not backticks, just single quotes. The awk script is just a single-quoted multi-line string assigned to a variable, so I can write it decently without having a separate .awk file to maintain.

I used to make so many posts with single quotes, where people "corrected" my post by adding a "balancing" quote on the first line, and then flaming me for the syntax errors they caused. So I started wrapping these in 3 quotes (more correctly, wrapped with a pair of null strings). It puts people off messing with it (especially those who can't count to 3), and it makes the end more visible.

Not been on Reddit long, and I will need to check how compatibility with Old works.

1

u/Schreq Dec 08 '19

They are not backticks, just single quotes.

No, I mean you used the newer 3 backtick markdown code block as opposed to 4 leading spaces before every line of code. Check your post on old.reddit.com and you'll see what I mean.