One question to understand multiple parameters of sort command in Linux

One question to understand multiple parameters of sort command in Linux

The sort command is very commonly used, but it also has many parameters, such as: -o, -n, -u, -r, and you may not be able to remember how to use it at the moment. Here is a question that can be well combined with the above parameters to achieve a good memory effect.

Title: The data file data contains the following data:

4
1
3
5
1001
2
4
5

Please use one command to reverse the sort, remove duplicates and save the data in the data file as well. Final output:

1001
5
4
3
2
1

To achieve the above three requirements, we need to use the above parameters at the same time. The specific commands are as follows:

[root@localhost ~]# cat data | sort -nur -o data
1001
5
4
3
2
1

Remark:

  • -u parameter # Remove duplicates
  • -n parameter # Sort by natural numbers instead of ASCII
  • -r parameter # sort in descending order
  • -o parameter # write the file to the file instead of standard output

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Detailed explanation of Linux text processing command sort
  • Detailed explanation of sort command in Linux text processing tool
  • Usage of linux sort command
  • Two ways to install mbstring extension in PHP under Linux system
  • How to install and use Linux Xtrabackup
  • How to add PHP extension module mbstring independently under Linux
  • Detailed explanation of Linux commands sort, uniq, tr tools

<<:  CocosCreator Getting Started Tutorial: Network Communication

>>:  Detailed explanation of the order of Mysql query results according to the order of ID in in()

Recommend

Detailed explanation of sshd service and service management commands under Linux

sshd SSH is the abbreviation of Secure Shell, whi...

Detailed explanation of mysql trigger example

Table of contents What is a trigger Create a trig...

The 6 Most Effective Ways to Write HTML and CSS

This article shares the 6 most effective methods,...

Summary of Node.js service Docker container application practice

This article will not explain the use and install...

An example of how Vue implements four-level navigation and verification code

Effect: First create five vue interfaces 1.home.v...

How to build an ELK log system based on Docker

Background requirements: As the business grows la...

Some questions about hyperlinks

<br />I am very happy to participate in this...

Getting Started Guide to MySQL Sharding

Preface Relational databases are more likely to b...

React's method of realizing secondary linkage

This article shares the specific code of React to...

Use of Linux network configuration tools

This article introduces RHEL8 network services an...

How to use MySQL stress testing tools

1. MySQL's own stress testing tool - Mysqlsla...

Detailed example of mysql trigger usage

MySQL trigger syntax details: A trigger is a spec...

jQuery implements form validation function

jQuery form validation example / including userna...

How to disable the automatic password saving prompt function of Chrome browser

Note: In web development, after adding autocomplet...

How to use IDEA to create a web project and publish it to tomcat

Table of contents Web Development 1. Overview of ...