Raspberry Pi_Eng_10.9.3 “sort” Command


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


10.9.3  "sort" Command

 

This command sorts the data in the specified file according to certain rule and then exports them to standard output.

 

[Command Format]

sort   [option]   [directory/file]

 

[Command Overview]

   This sorts the data in the specified file.

   User privilege          -- Normal user.

 

[Detail Description]

   None

 

[Main Option]

-b, --ignore-leading-blanks

ignore leading blanks

-d, --dictionary-order

consider only blanks and alphanumeric characters

-f, --ignore-case

fold lower case to upper case characters

-g, --general-numeric-sort

compare according to general numerical value

-r, --reverse

reverse the result of comparisons

 

[Used Example]

First, there is a file "customer_list.txt" in the "testdata" directory of the "pi" account, and the contents are as follows.

 

pi@raspberrypi ~/testdata $ cat customer_list.txt

Microsoft

Google

IBM

Facebook

LG

Samsung

Sony

Hewlett-Packard

 

Now let's run the "sort" command on this file. The result is as follows. You can see that the output is listed in sorted manner.

 

pi@raspberrypi ~/testdata $ sort customer_list.txt

Facebook

Google

Hewlett-Packard

IBM

LG

Microsoft

Samsung

Sony

 

This time we will do the same work with "-r" option. You can see that the sorted data is listed in reverse order to the above example.

 

pi@raspberrypi ~/testdata $ sort -r customer_list.txt

Sony

Samsung

Microsoft

LG

IBM

Hewlett-Packard

Google

Facebook