Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case Sensitive Sort Unix Bash

Tags:

bash

unix

sorting

Here is a screenshot of an issue I'm having with sort:

http://i.imgur.com/cIvAF.png

The objective I want out of this, is to put all equal strings on consecutive lines. It works for 99% of the list I'm sorting, but there's a few hitches such as those in the screen shot.

So all the yahoo.coms should be next to each other, and then all the Yahoo.coms then the YAHOO.coms yahoo.cmos yhoo.c etc. (The typos even getting their own group of lines)

Not entirely sure how to handle this with sort, but I'm certainly trying.

I print all the domains unsorted to a file and then sort it with just vanilla sort filename

Would love some advice/input.

like image 443
Wuzseen Avatar asked Apr 26 '12 03:04

Wuzseen


People also ask

Are Unix path case sensitive?

Unix & Linux typically use case-sensitive filesystems, so there is a distinct difference between A. txt and a. txt .

Is bash command case sensitive?

Variables in Bash Scripts are untyped and declared on definition. Bash also supports some basic type declaration using the declare option, and bash variables are case sensitive.

Which option represents case-insensitive sorting in Linux?

By default the sort tool will sort uppercase characters first. To sort and ignore case use the -f option.


1 Answers

You probably need to override the locale; most Linux systems default to a UTF8 locale which specifies both case independent sorting and ignoring punctuation.

LANG=C sort filename
like image 127
geekosaur Avatar answered Sep 26 '22 18:09

geekosaur