Detailed explanation of Linux text processing command sort

Detailed explanation of Linux text processing command sort

sort Sort the contents of a text file

Usage: sort + option + file name (can be followed by multiple files)

Example 1: cat 1.txt

sort 1.txt #text, sorted by letters az by default

Example 2: cat 2.txt

sort 2.txt #Numbers, sorted by 1-9 by default

-n parameter: sort -n 2.txt #Add -n to sort the numbers from small to large

-r parameter: sort -n -r 2.txt #-r, sort in reverse order (also applies to text)

If a text has two columns, it is sorted by the first column by default. Example: cat 3.txt

sort 3.txt #Default sorting is by the first column

-t parameter: specify the delimiter

-k parameter: specifies the column to be sorted

Example: sort -t ',' -k2 3.txt #Use comma ',' as the delimiter to sort the second column

Similarly: sort -t ',' -k2n 3.txt # Sort by the second column number from small to large

sort -t ',' -k2nr 3.txt #Sort by the second column number from large to small

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:
  • One question to understand multiple parameters of sort command in Linux
  • 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

<<:  Detailed explanation of CocosCreator MVC architecture

>>:  jQuery plugin to achieve image suspension

Recommend

ThingJS particle effects to achieve rain and snow effects with one click

Table of contents 1. Particle Effects 2. Load the...

13 Most Frequently Asked Vue Modifiers in Interviews

Table of contents 1. lazy 2.trim 3.number 4.stop ...

Implementation of Nginx hot deployment

Table of contents Semaphore Nginx hot deployment ...

SSH port forwarding to achieve intranet penetration

The machines in our LAN can access the external n...

Working principle and example analysis of Linux NFS mechanism

What is NFS? network file system A method or mech...

Summary of MySQL Undo Log and Redo Log

Table of contents Undo Log Undo Log Generation an...

React's component collaborative use implementation

Table of contents Nesting Parent-child component ...

CSS3 transition to implement notification message carousel

Vue version, copy it to the file and use it <t...

Classification of web page color properties

Classification of color properties Any color can ...

Detailed explanation of importing/exporting MySQL data in Docker container

Preface We all know that the import and export of...

Reasons and solutions for the failure of React event throttling effect

Table of contents The problem here is: Solution 1...

Two ways to make IE6 display PNG-24 format images normally

Method 1: Please add the following code after <...

How to purchase and initially build a server

I haven't worked with servers for a while. No...