Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Interesting example of Linux Sort command     - Access clipboard content across multiple vim instances in a terminal (Linux)

- To set up the printer use Nagios Monitoring Server (Server)

- Ubuntu Froxlor Server Administration panel installation (Server)

- to install the deployment of LVS under CentOS 7.0 (Server)

- MySQL5.6.12 Waiting for commit lock lead to hang from the library housing problem analysis (Database)

- Experience CoreCLR stack unwinding characteristics of initial implementation on Linux / Mac (Linux)

- RHEL 6.5 x86_64 CentOS yum configuration source (Linux)

- Ubuntu 15.04 using the Eclipse 4.4, Java 8 and WTP (Linux)

- MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB (Database)

- innodb storage engine backup tool --Xtrabackup (Database)

- Install NetBeans IDE 8.0 on Ubuntu, Linux Mint, Elementary OS, and Debian (Linux)

- Oracle RMAN repair logical bad blocks (Database)

- Easy to get hidden administrator account (Linux)

- How to use Aptik to backup and restore Apps/PPAs under ubuntu (Linux)

- C ++ 11 feature: auto keyword (Programming)

- Java call by value and by reference (Programming)

- Use top to monitor the remote server (Server)

- Oracle table compression Technology Introduction (Database)

- IBM Data Studio to create objects using ---- double quotes / sensitive issues and the table / column renaming (Database)

- Linux system package manager (rpm, yum, source packages installation) (Linux)

 
         
  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:      
 
- Extended VMware Ubuntu root partition size (Linux)
- LogStash log analysis display system (Linux)
- Spring Data study notes -Helloworld (Programming)
- The source code compiler installation Nginx 1.8.0 under Ubuntu 14.10 (Server)
- Install Mac OS X 10.9 systems VMware10 (Linux)
- Apache Linux firewall reverse proxy configuration (Linux)
- Installation and Configuration rsync server under CentOS 6.3 (Server)
- Vim configuration instructions (Linux)
- Oracle 11g dataguard main library backup and recovery to the test environment in one database error (Database)
- Delete specific files using bash directory under Linux (Linux)
- Oracle () trunc function usage (Database)
- FreeRadius installation process record (Linux)
- Zypper command for SUSE Linux package management (Linux)
- Supervisor Installation and Configuration (Server)
- Linux / Unix: chroot command examples to explain (Linux)
- Install JDK 1.7 + Eclipse in CentOS 6.4 in (Linux)
- Linux cut Command Study Notes (Linux)
- Ubuntu arm-none-eabi-gcc compiler treated with STM32F10x (Linux)
- 29 practical examples Linux system / network administrator of nmap (Linux)
- CentOS7 virtual machine settings, and bridging problems (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.