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

Implementing search box function with search icon based on html css

Preface Let me share with you how to make a searc...

Complete Tutorial on Deploying Java Web Project on Linux Server

Most of this article refers to other tutorials on...

VMware installation of Centos8 system tutorial diagram (Chinese graphical mode)

Table of contents 1. Software and system image 2....

CSS3 realizes various graphic effects of small arrows

It’s great to use CSS to realize various graphics...

Detailed explanation of the calculation method of flex-grow and flex-shrink in flex layout

Flex(彈性布局) in CSS can flexibly control the layout...

Trash-Cli: Command-line Recycle Bin Tool on Linux

I believe everyone is familiar with the trashcan,...

Detailed explanation of Xshell common problems and related configurations

This article introduces common problems of Xshell...

Creating a Secondary Menu Using JavaScript

This article example shares the specific code of ...

jQuery implements breathing carousel

This article shares the specific code of jQuery t...

Share 16 burning flame effect English fonts treasure trove

We live in a visual world and are surrounded by m...

How to start a Java program in docker

Create a simple Spring boot web project Use the i...