Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Interesting example of Linux Sort command     - CentOS 7 server environment to quickly build Linux (Server)

- Use Aptik Battery Monitor monitoring Ubuntu laptop battery usage (Linux)

- Android 4.2 compilation notes (Programming)

- Linux Detailed instructions alias settings (Linux)

- Ubuntu Linux Change the PATH (Linux)

- CentOS6.3 build a Python 3.3 environment to access Oracle 11gR2 (Database)

- CentOS 5.5 install ntop (Linux)

- RHEL7.0 log system (Linux)

- Linux (CentOS) SSH login without password authentication (Linux)

- Installation of Theano + CUDA under Ubuntu (Linux)

- The correct way of logical backup mysqldump (Database)

- jobs command example (Linux)

- Linux / Unix system-level IO (Linux)

- Ubuntu 14.04 running ASP.NET Configuration Mono + Jexus (Server)

- In-depth understanding of capture Node.js garbage collection and memory leaks (Programming)

- Shuffle Process Arrangement in MapReduce (Server)

- Cryptography development environment to build under Ubuntu (Linux)

- Struts2 : combobox label use (Programming)

- C ++ Const breaking rules (Programming)

- Android Studio quick overview of Gradle (Programming)

 
         
  Interesting example of Linux Sort command
     
  Add Date : 2017-01-08      
         
         
         
  In the last article, we have explored a number of examples of the sort command, if you missed the article, you can click on the following link to read. Today's article as the article continues, will discuss the remaining usage of the sort command, together with the previous one as Linux 'sort' a complete guide to the command.

1, useful example Linux Sort command (a)

Before we go further, to create a text document 'month.txt', and the data on a given filling inside.

$ Echo -e "mar \ ndec \ noct \ nsep \ nfeb \ naug"> month.txt
$ Cat month.txt

2, by using the 'M' option to 'month.txt' files sorted by month order.

$ Sort -M month.txt
Note: 'sort' command requires at least three characters to confirm the name of the month.

3, easy to organize your data into human-readable form, such as 1K, 2M, 3G, 2T, there's a K, G, M, T on behalf of one thousand, trillion, Kyrgyzstan, ladder. (LCTT Annotation: here is wrong command, ls command should increase -h parameter, the diameter corrections)

$ Ls -lh / home / $ USER | sort -h -k5

4, in the last article, we created in the example 4 a file named 'sorted.txt', creating a 'lsl.txt' in Example. 'Sorted.txt' already sorted, and 'lsl.txt' yet. Let's use the sort command to check whether two files are already sorted.

$ Sort -c sorted.txt
Check File is Sorted

If it returns 0, the file is already sorted.

$ Sort -c lsl.txt

Report disorder. Contradictions ......

5, if the delimiter is a space between words, sort command automatically something new space after the word as a unit, if the delimiter is not a space it?

Consider a text file, the contents of which may consist of any sign, except space separated, for example, '|' '.', '\', '+', And so on ......

+ Create a delimiter text file. Using the 'cat' command to view the contents of the file.

$ Echo -e "21 + linux + server + production \ n11 + debian + RedHat + CentOS \ n131 + Apache + Mysql + PHP \ n7 + Shell Scripting + python + perl \ n111 + postfix + exim + sendmail"> delimiter.txt
$ Cat delimiter.txt

Now based on the first domain consisting of numbers to be sorted.

$ Sort -t '+' - nk1 delimiter.txt

Then on the fourth non-numeric domain order.

If delimiter is a tab that you need in the '+' position with $ '\ t' instead of, as in the example below.

6, on the main user directory using the result 'ls -l' command obtained based on the fifth column ( 'file size') were arranged in a random order.

$ Ls -l / home / avi / | sort -k5 -R

Every time you run the above script, you get the results may be different, because the results are randomly generated.

As I mentioned in the rules of the article 2 of said --sort command line will start with a lowercase letter came in the front row of capital letters began. Look at cases on article 3, the string 'laptop' in 'LAPTOP' before appear.

7, how to override the default sort priority? Prior to this we need to first set the value of the environment variable LC_ALL to C. At the command line prompt to run the following bar code.

$ Export LC_ALL = C
Then a non-default priority manner 'tecmint.txt' file reordered.

$ Sort tecmint.txt

Sort priority coverage

Do not forget to resemble the results obtained in example 3 for comparison, and you can use the '-f', also known as '-ignore-case' (ignore case) option to obtain more orderly output.

$ Sort -f tecmint.txt

8, to two input files 'sort', and then connect them in a row!

We created two text documents 'file1.txt' and 'file2.txt', and fill it with data, as shown below, and use the 'cat' command to view the contents of the file.

$ Echo -e "5Reliable \ n2Fast \ n3Secure \ n1 open-source \ n4 customizable"> file1.txt
$ Cat file1.txt

With the following data to populate 'file2.txt'.

$ Echo -e "3RedHat \ n1Debian \ n5Ubuntu \ n2Kali \ n4Fedora"> file2.txt
$ Cat file2.txt

Now we have two sort files and connect.

$ Join <(sort -n file1.txt) <(sort file2.txt)

The entire contents of my argument here, I hope to keep in touch with you, I hope you always come around. Feedback in the comments below it.
     
         
         
         
  More:      
 
- To install the Oracle 10.2.0.1.0 process notes on Oracle Linux 4u4 (Database)
- How Bluetooth turned off by default in Ubuntu 14.04 (Linux)
- Ubuntu 14.04 jdk Installation and Configuration (Linux)
- Linux 64-bit porting (Programming)
- Oracle restrict certain IP, the malicious user actions on important table (Database)
- Recent Consolidation Using Linux security module (Linux)
- Redis 3.0.3 Cluster Setup (Database)
- Node.js Getting the basics: Helloworld! (Linux)
- When the master key encounter NULL (Database)
- Python image processing library (PIL) to install and simple to use (Linux)
- Linux System Getting Started Learning: Using yum to download the RPM package without installing (Linux)
- RabbitMQ user roles and access control (Linux)
- Oracle Linux 5.5 (64bit) Install Oracle 11gR2 RAC detailed tutorial (Database)
- Ubuntu dual-card system configuration method (Server)
- Linux operating process information (Linux)
- MySQL to recover the data through binlog (Database)
- Nginx supports user multi-threaded downloads and resume broken (Server)
- Spacewalk remove packages install the update (Linux)
- C ++ Object Model Comments (Programming)
- Linux operating system Start Tutorial: Xmanager Remote Access Linux graphical interface (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.