shell: sort (sort the contents of the text file)

sort, as the name implies, is sorting

  • -b Ignore the space characters at the beginning of each line.
  • -c Check whether the files have been sorted in order.
  • -d When sorting, deal with English letters, numbers and space characters, and ignore other characters.
  • -f When sorting, treat lowercase letters as uppercase letters.
  • -i When sorting, in addition to the ASCII characters between 040 and 176, other characters are ignored.
  • -m Combine several sorted files.
  • -M Sort the first 3 letters according to the abbreviation of the month.
  • -n Sort according to the magnitude of the value.
  • -u means unique (unique), and the output result is finished.
  • -o<output file> Save the sorted results to the specified file.
  • -r Sort in reverse order.
  • -t<separation character> Specifies the field separator character used when sorting.
  • +<Start field>-<End field> Sort by the specified field, ranging from the start field to the previous field of the end field.
  • --help Display help.
  • --version Display version information. 
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# cat baichao.txt
c
c++
linux
c#
Mysql
Oracle
linux
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort baichao.txt
c
c#
c++
linux
linux
Mysql
Oracle
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort -u baichao.txt
c
c#
c++
linux
Mysql
Oracle
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort -r baichao.txt
Oracle
Mysql
linux
linux
c++
c#
c
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort -r baichao.txt -o baichao.txt
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# cat baichao.txt
Oracle
Mysql
linux
linux
c++
c#
c

There is also a more special case is the number sort

root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# cat baichao1.txt
1
111
2
222
3
4
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort baichao1.txt
1
111
2
222
3
4
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort -n baichao1.txt
1
2
3
4
111
222

Sorted files to merge 

root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# cat baichao.txt
c
c#
c++
linux
linux
Mysql
Oracle
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# cat baichao1.txt
1
2
3
4
111
222
root@iZ2zeckzw4ww9d0umka1vqZ:/home/baichao/linux/shell/sort# sort -m baichao.txt baichao1.txt
1
2
3
4
111
222
c
c#
c++
linux
linux
Mysql
Oracle

 

Guess you like

Origin blog.csdn.net/weixin_40179091/article/details/113698706