5 Event Of Course Ascendancy Inwards Unix Or Linux >>>> Unix Tutorial

Sorting is 1 of the essential tasks nosotros ever demand to perform too UNIX or Linux has non bad back upwards for sorting past times using sort command. No affair what form of trounce script y'all are writing or y'all are looking for around information or reports many times y'all demand to sort the output of 1 ascendency or a ready of line, amongst a combination of the sort amongst find ascendency and grep inward UNIX y'all tin grip back upwards asking too study quite easily. In this UNIX sort ascendency tutorial, nosotros volition run across how nosotros tin survive sort ascendency inward UNIX to attain our sorting goal. This tutorial contains around of the practical example of sort command for sorting information inward UNIX. With the survive of “unique” too “sort” command, y'all tin take away duplicates too acquaint a sorted information inward UNIX.

Now let’s run across what UNIX sort ascendency tin arrive at for us using five examples of UNIX sort commands, I convey tested these commands on Cygwin running on Windows XP too I await it plant fine on other OS e.g. Redhat Linux, Solaris or IBM AIX because it's pretty basic command, Please allow me know if y'all confront whatever termination spell using these Unix sort examples on whatever other OS. I idea close writing on Sort ascendency when I was working on 10 tips to piece of job fast inward Unix too UNIX ascendency tutorial too Example for beginners only somehow I am publishing it quite late. Anyway, directly y'all convey Some Example of Sort ascendency inward UNIX to sort your files too directory equally per your need.



UNIX or Linux Sort Command Examples

1) Sorting based on numeric value of String using UNIX sort command:
Sorting is 1 of the essential tasks nosotros ever demand to perform too UNIX or Linux has grea five instance of sort ascendency inward UNIX or Linux   >>>>  Unix TutorialMany times instead of alphabetic sorting nosotros demand numeric sorting. Just similar inward below instance of Unix sort ascendency if nosotros desire to sort based upon a numeric value of PID nosotros tin survive sort -n along amongst sort -k(column). Since hither PID is mo column sort -nk2 volition piece of job for us. This is likewise around other non bad instance of UNIX sort past times column, which allows you arrive at sort the information based on whatever column inward UNIX.


unix-sort-examples@unix-tutorial: /test ps -ef | sort -nk2
UID                  PID       PPID TTY     STIME COMMAND
unix-sort-examples     500    2832   0    Jul xviii /usr/bin/bash
unix-sort-examples    1976    3556   2    Jul18 /usr/bin/ps
unix-sort-examples    2324       1 con    Jul xviii /cthelper
unix-sort-examples    2676       1 con    Jul xviii /cthelper
unix-sort-examples    2832       1 con    Jul xviii /cthelper
unix-sort-examples    3332    2676   1    Jul xviii /usr/bin/bash
unix-sort-examples    3556    2324   2    Jul xviii /usr/bin/bash




2) Reverse sort past times using UNIX sort command
Sometimes nosotros demand to sort inward contrary club e.g. descending order. sort -r option allows us to perform contrary sorting inward Unix.

unix-sort-examples@unix-tutorial: /test ps -ef | sort -rnk2
unix-sort-examples    3616    3556   2  11:49:43 /usr/bin/ps
unix-sort-examples    3556    2324   2    Jul xviii /usr/bin/bash
unix-sort-examples    3448       0   0    Jan  1 /usr/bin/ps
unix-sort-examples    3332    2676   1    Jul xviii /usr/bin/bash
unix-sort-examples     500    2832   0    Jul xviii /usr/bin/bash
     UID     PID    PPID TTY     STIME COMMAND



3) UNIX sort past times column : Sorting based on whatever column inward the input.
sort ascendency inward Unix to a greater extent than oft than non used inward combination of other Unix commands similar find, grep, ls or ps too most of these commands arrive at output inward tabular format too nosotros desire to sort based on whatever column. Unix sort command allows us to arrive at this past times using sort -k option. Let's run across an instance or Unix sort ascendency to sort the output on whatever column nosotros volition survive ps ascendency output for this instance too we volition sort this output on column 2 (PID) too after on column iii (PPID)

unix-sort-examples@unix-tutorial: /test ps -ef | sort -nk2
     UID     PID    PPID TTY     STIME COMMAND
unix-sort-examples     500    2832   0    Jul xviii /usr/bin/bash
unix-sort-examples    2324       1 con    Jul xviii /cygdrive/c/Software/puttycyg-20101029/puttycyg-20101029/cthelper
unix-sort-examples    2564       0   0    Jan  1 /usr/bin/bash
unix-sort-examples    2676       1 con    Jul xviii /cygdrive/c/Software/puttycyg-20101029/puttycyg-20101029/cthelper
unix-sort-examples    2832       1 con    Jul xviii /cygdrive/c/Software/puttycyg-20101029/puttycyg-20101029/cthelper
unix-sort-examples    3332    2676   1    Jul xviii /usr/bin/bash
unix-sort-examples    3556    2324   2    Jul xviii /usr/bin/bash
unix-sort-examples    3764    3556   2  11:58:08 /usr/bin/ps

unix-sort-examples@unix-tutorial: /test ps -ef | sort -nk3
     UID     PID    PPID TTY     STIME COMMAND
unix-sort-examples    2324       1 con    Jul xviii /cygdrive/c/Software/puttycyg-20101029/puttycyg-20101029/cthelper
unix-sort-examples    2676       1 con    Jul xviii /cygdrive/c/Software/puttycyg-20101029/puttycyg-20101029/cthelper
unix-sort-examples    2832       1 con    Jul xviii /cygdrive/c/Software/puttycyg-20101029/puttycyg-20101029/cthelper
unix-sort-examples    3556    2324   2    Jul xviii /usr/bin/bash
unix-sort-examples    3332    2676   1    Jul xviii /usr/bin/bash
unix-sort-examples     500    2832   0    Jul xviii /usr/bin/bash
unix-sort-examples     184    3556   2  11:58:21 /usr/bin/ps

You tin likewise sort based upon multiple columns using sort ascendency equally a sort -nk23 volition sort the output kickoff on the mo column too hence on tertiary column.



4) Sorting output on alphabetical club past times using UNIX sort command
In this instance of UNIX sort command, nosotros volition run across how to sort the output of whatever ascendency inward alphabetical order. Sort ascendency inward UNIX sorts the output inward alphabetic club if y'all don't render whatever options equally shown inward below example.

unsorted output
unix-sort-examples@unix-tutorial: /test truthful cat names
stocks trading
futures trading
options trading
forex trading
electronic trading

sorted output
unix-sort-examples@unix-tutorial: /test truthful cat names | sort
electronic trading
forex trading
futures trading
options trading
stocks trading



5) How to take away duplicates from sorted output inward UNIX
As y'all convey seen inward in a higher house instance of sort ascendency inward UNIX nosotros convey duplicates "stock trading" is coming ii times. We tin arrive at sorted output without duplicates inward ii ways inward UNIX either past times passing output of sort ascendency to "uniq" command or past times using sort -u option. Let’s run across an instance of sorting amongst unique elements using UNIX sort command:

Sorted output amongst duplicates
unix-sort-examples@unix-tutorial: /test cat names | sort
electronic trading
forex trading
stocks trading
stocks trading

Sorted output without duplicates
unix-sort-examples@unix-tutorial: /test cat names | sort | uniq
electronic trading
forex trading
stocks trading

unix-sort-examples@unix-tutorial: /test cat names | sort -u
electronic trading
forex trading
stocks trading  



That’s all for directly on Unix sort command. Please portion how are y'all using sort ascendency inward Unix , how useful y'all uncovering UNIX sort ascendency too is at that topographic point whatever other alternative of Unix sort inward other OS e.g. Redhat Linux, Solaris or IBM AIX ?

Further Learning
Linux Command Line Basics
What are Special bash parameters inward Unix


Komentar

Postingan populer dari blog ini

Common Multi-Threading Mistakes Inwards Coffee - Calling Run() Instead Of Start()

3 Examples Of Parsing Html File Inwards Coffee Using Jsoup

Why You Lot Should Command Visibility Of Shape Too Interface Inward Java