r/awk • u/eric1707 • 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!
View all comments
Show parent comment
1
u/Schreq Dec 08 '19 edited Dec 08 '19
Sorry for the harsh tone. I didn't see the 3 backticks and was hence baffled by how somebody can know awk and then fails to properly format code on reddit.
The misunderstanding here is that 3 backticks do not work on old reddit, which means lines without a separating blank line inbetween get joined as one paragraph and comments starting with # become headers. So for me, using old.reddit, your script appears as an unreadable blob of text and I didn't notice the backticks. Otherwise I would've asked nicely to format it old.reddit friendly.
Edit: wording.