0

If I have a file with some words starting with Capital letters and some starts with Small letters and some start with numbers or special characters. Does using sort -u input > output convert the letter in the input file to lower case in the output file?

For some reason this seems what happened with me. However, if not, I need a method to first convert the capital letters initials if found to small.

  • You can easily test your assumption by running printf "World\nhello\nworld\nHello" | sort -u in bash or similar. – nohillside Apr 9 at 18:35
  • Having said that, it's a bit unclear what your question actually is. Do you want to know about sort behaviour, about a way to convert upper to lower case for sorting, or about something else? – nohillside Apr 9 at 18:36
  • Do you have sample data that behaved in an unexpected way? If so, please edit it into your question. Thank you! – Jeff Schaller Apr 9 at 18:42
3

sort does not alter case, nor does sort change the data other than ordering, notwithstanding sort -u which removes duplicates.

$ for demochar in a b c A B C Ɓ ƀ À à; do printf "%s\n%s\n" "$demochar" "$demochar"; done ) | shuf > input1
$ sort -u input1  > input2
$ sort -uf input1 > input3
$ paste input1 input2 input3
B   A   a
ƀ   B   B
C   C   C
C   a   à
B   b   ƀ
b   c   Ɓ
à   À
a   à
à   ƀ
c   Ɓ
c
A
ƀ
Ɓ
a
b
Ɓ
A
À
À

sort -f will for the purposes of the comparison, force everything to upper case that it can, but it does not change the actual data being output. From the manual:

-f, --ignore-case

Convert all lowercase characters to their uppercase equivalent before comparison, that is, perform case-independent sorting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.