Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Interesting example of Linux Sort command     - Android will save the picture to see the album and timely (Programming)

- CentOS7 + Redis Live Installation and Configuration (Linux)

- Caffe + Ubuntu 14.04 64bit + CUDA 6.5 configuration instructions (Linux)

- Those things packaged using Gradle to Android (Programming)

- When should I use Angular 2 (Programming)

- Traffic monitor Linux Python Version (Programming)

- Varnish achieve page jump (Server)

- Install Apache streaming media services on CentOS 6.4 (Server)

- Linux common commands MEMO (Linux)

- MySQL 5.6.12 binary log path switching binlog (Database)

- Linux system find command Detailed (Linux)

- Binary tree to the next node (Programming)

- Vim useful plugin: vundle (Linux)

- Use small network command to check whether PC Security (Linux)

- Elementary OS Freya global menu (Linux)

- Using open source software to build XWiki Wiki system installed within the company (Linux)

- SUSE Firewall Configuration (Linux)

- DRBD + Heartbeat solve NFS single point of failure (Server)

- How to modify the Ubuntu terminal user name changed to red color (Linux)

- Java to achieve local fileCopy (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.
- Android custom slideshow menu slidmenu (Programming)
- Impact test noatime Linux file access time (Linux)
- Java multi-threaded communications pipeline flow (Programming)
- KVM virtualization nested configuration (Server)
- C language programming entry - macro definitions and enum (Programming)
- Awk include binding capacity larger than the specified size of all files directory (Linux)
- MySQL 5.6 Open full query log (Database)
- Using Linux stat command to view the files (Linux)
- Linux system font color change (Linux)
- Installation and Configuration JDK8 In CentOS 7 (Linux)
- grep command Series: grep command to search for multiple words (Linux)
- Installation Elementary OS Freya to do some settings (Linux)
- Ubuntu prevent arp attacks (Linux)
- To use Android RecyclerView (Programming)
- Security basics: simple analytical framework for Linux system firewall (Linux)
- New features of Java 9 HTTP2 and REPL (Programming)
- Getting Started with Linux system to learn: how to get the process ID (PID) in the script (Linux)
- The first deployment of cross-platform operation Rafy record (Server)
- MySQL High Availability plan several options (Database)
- Java precision four operations (Programming)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.