-1

I have some text files where I wanted to filter some things just to practice some Linux commands.

I tried to use sort. The problem is that I don't see a difference with sort -b.

I tried the following commands:

  • cat text.txt | sort
  • cat text.txt | sort -b

I didn't notice any difference between both outputs. Maybe I don't really understand what leading blanks mean. Can someone explain me what does it mean? Also, it could help me if you can give me an example of text where -b does affect the filtering of sort.

Thanks.

0

Whether you see a difference or not probably depends on your locale (specifically, LC_COLLATE) i.e. whether space characters come before or after alphabetic characters in the collation order.

For example,

$ cat fileb
 xyz
  pqr
abc
jkl

in my default locale sorts alphabetically regardless of the -b switch; however

$ LC_COLLATE="C" sort fileb
  pqr
 xyz
abc
jkl

whereas

$ LC_COLLATE="C" sort -b fileb
abc
jkl
  pqr
 xyz
  • What is my locale and LC_COLLATE? – Pichi Wuana Sep 17 '16 at 15:02
  • @PichiWuana you should be able to get a list of variables describing your current locale simply by typing locale at the command prompt.See also man locale. – steeldriver Sep 17 '16 at 15:14
  • Ooh... I get it. In my case it's written LC_COLLATE ="en_US.UTF-8". Could you explain how does -b work for my case? – Pichi Wuana Sep 17 '16 at 15:17

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.