Function Description: Sort the text file content.
Syntax: sort [-bcdfimMnr][-o<output file>][-t<separation character>][+<starting field>-<end field>] [--help][--verison][file]
Note: Sort can sort the content of text files in units of rows.
Parameters: -b Ignores the space character that begins before each line. -c Checks if the files are sorted in order. -d Sorts, except for English letters, numbers, and space characters, ignoring other characters. -f When sorting, treat lowercase letters as uppercase letters. -i When sorting, except for ASCII characters between 040 and 176, other characters are ignored. -m Combines several sorted files. -M Sorts the first 3 letters according to the abbreviation of the month. -n Sort by size. -o<output file> Saves the sorted result to the specified file. -r Sorts in reverse order. -t<separator character> Specifies the field separator character to use when sorting. +<Start Field>-<End Field> Sort by the specified field, from the start field to the previous field of the end field. --help Displays help. --version Display version information
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following uses a few examples to describe the use of Sort.
Use the Sort command to sort the lines in the text file and output the result. Note that the first word on the second and third lines of the original file is identical, and the command will continue to compare from their second word, vegetables, with the first character of the fruit.
$ cat text
vegetable soup
fresh vegetables
fresh fruit
lowfat milk
$ Sort text
fresh fruit
fresh vegetables
lowfat milk
vegetable soup
Users can save sorted files or sort them The contents of the file are output to the printer. In the following example, the user saves the sorted file contents to a file named result.
$ Sort text>result
Sort the contents of the file example with the second field as the sort key.
$ Sort +1-2 example
For the reverse sorting of file1 and file2 files, the result is placed in outfile, using the first character of the second field as the sort key.
$ Sort -r -o outfile +1.0 -1.1 example
Sort sorting is often used in conjunction with other commands in the pipeline to combine more complex functions, such as using the pipeline to the current working directory. The files in the file are sorted by Sort, and the sort key is the 6th to 8th fields.
$ ls - l |
Sort +5 - 7
$ ps -e -o " comm pid time"|
Sort -d //Sort alphabetically according to the first letter of the command
The Sort command can also operate on standard input. For example, if you want to merge several lines of text and sort the merged lines of text, you can first merge the multiple files with the command cat and then pipe the merged lines of text into the command Sort. The Sort command will output these merged and sorted lines of text. In the following example, the text line of the file veglist and the file fruitlist are merged and sorted and saved to the file clist.
$ cat veglist fruitlist |
Sort > clist
With the rapid development of the Internet, more and more people use computers to obtain information
Linux 2.6 device drivers are built on the basis of the device model, therefore, to write device driv
On the linux device model online, there are some discussions, some things I used to use, to modify a
Will the Linux server crash? Of course, I have been exposed to a certain type of server. After inst
6 emergency handling tips in the Linux operating system
Linux signal signal processing mechanism
About gdb command knowledge in Linux system
Linux Network Operation Command Encyclopedia
The shell script automatically modifies the IP information
The Linux find command uses the tutorial
Linux shell awk get external variables (variable value) Introduction
Oracle, informix database environment variable settings and compile
How to configure chroot SFTP in Linux
In 2014, 13% of the updates released by Microsoft had problems
Sharing experience: Let Windows 7 easily recognize Real-format video files
Windows7 command prompt environment DOS command failure
Step laptop connected to a projector
Win7 always shows "software application is not compatible" solution
Notebook Vista power saving program