How to use sort text processing commands in Linux
This article shows you how to use the sort text processing command in Linux. It is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.
sort Sort the contents of a text file
Usage: sort + option + filename (can be followed by multiple files)
Example 1: cat 1.txt
sort 1.txt #text, sorted by letters a-z by default
Example 2: cat 2.txt
sort2.txt #Numbers, sorted by default from 1-9
-n argument: sort -n 2.txt #plus-n, sort numbers from small to large
-r parameter: sort -n -r 2.txt #-r , reverse sort (also applies to text)
If a text has two columns of content, the default is sorted by the first column. Example: cat3.txt
sort3.txt #Sort by first column by default
-t parameter: specify delimiter
-k parameter: specifies the column to sort
Example: sort -t ',' -k2 3.txt #Sort the second column with comma ',' as separator
sort -t ',' -k2n 3.txt #Sort by the second column from smallest to largest
sort -t ',' -k2nr 3.txt #Sort by second column numbers from largest to smallest
Linux is a free-to-use and freely distributed UNIX-like operating system, is a POSIX-based multi-user, multitasking, multi-threaded and multi-CPU operating system, using Linux to run major Unix tools, applications and network protocols.
That's how to use the sort text processing command in Linux. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.