Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the common command sort in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how to use the common command sort in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The Linux common command sort command is used to sort the contents of the text file, and sort can sort the contents of the text file by behavior unit.

Syntax sort [- bcdfimMnr] [- o] [- t] [+ -] [--help] [--verison] [file] [- k field1 [, field2]] parameter description:

-b ignores space characters that begin at the beginning of each line.

-c check whether the files have been sorted in order.

When sorting, ignore other characters except alphabetic, numeric and space characters.

When sorting, lowercase letters are treated as uppercase letters.

When sorting, all characters except ASCII characters between 040 and 176are ignored.

-m merges several sorted files.

-M sorts the first three letters according to the abbreviation of the month.

-n is sorted by the size of the number.

-u means unique (unique), and the output is overweight.

-o saves the sorted results to the specified file.

-r is sorted in reverse order.

-t specifies the field delimiter used for sorting.

+-sorts by the specified field, ranging from the start field to the previous field of the end field.

-help displays help.

-version displays version information.

[- k field1 [, field2]] sorts by the specified column.

The instance is using the sort command to sort the lines of the file by default, using the following command:

The sort testfilesort command arranges the first column of the text file in the order of ASCII codes by default and outputs the results to standard output.

Using the cat command to display the testfile file shows that its original order is as follows:

The original sort of $cat testfile # testfile file test 30 Hello 95 Linux 85 is rearranged using the sort command as follows:

$sort testfile # rearrangement result Hello 95 Linux 85 test 30 rearranges the values of the second column using the-k parameter setting. The result is as follows:

$sort testfile-k 2test 30 Linux 85Hello 95 Thank you for reading! This is the end of the article on "how to use sort in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report