5 Example Of Course Ascendance Inwards Unix Or Linux >>>> Unix Tutorial

Sorting is ane of the essential tasks nosotros e'er demand to perform in addition to UNIX or Linux has non bad back upwards for sorting past times using sort command. No thing what sort of vanquish script you lot are writing or you lot are looking for around information or reports many times you lot demand to sort the output of ane ascendance or a ready of line, amongst a combination of the sort amongst find ascendance and grep inward UNIX you lot tin grip back upwards asking in addition to study quite easily. In this UNIX sort ascendance tutorial, nosotros volition come across how nosotros tin purpose sort ascendance inward UNIX to accomplish our sorting goal. This tutorial contains around of the practical example of sort command for sorting information inward UNIX. With the purpose of “unique” in addition to “sort” command, you lot tin take away duplicates in addition to acquaint a sorted information inward UNIX.

Now let’s come across what UNIX sort ascendance tin orbit for us using five examples of UNIX sort commands, I accept tested these commands on Cygwin running on Windows XP in addition to I facial expression it industrial plant fine on other OS e.g. Redhat Linux, Solaris or IBM AIX because it's pretty basic command, Please allow me know if you lot human face upwards whatever upshot spell using these Unix sort examples on whatever other OS. I idea well-nigh writing on Sort ascendance when I was working on 10 tips to function fast inward Unix in addition to UNIX ascendance tutorial in addition to Example for beginners merely somehow I am publishing it quite late. Anyway, straightaway you lot accept Some Example of Sort ascendance inward UNIX to sort your files in addition to 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 ane of the essential tasks nosotros e'er demand to perform in addition to UNIX or Linux has grea five instance of sort ascendance inward UNIX or Linux   >>>>  Unix TutorialMany times instead of alphabetic sorting nosotros demand numeric sorting. Just similar inward below instance of Unix sort ascendance if nosotros desire to sort based upon a numeric value of PID nosotros tin purpose sort -n along amongst sort -k(column). Since hither PID is minute column sort -nk2 volition function for us. This is likewise around other non bad instance of UNIX sort past times column, which allows you orbit 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 opposite guild e.g. descending order. sort -r option allows us to perform opposite 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 ascendance inward Unix by in addition to large used inward combination of other Unix commands similar find, grep, ls or ps in addition to most of these commands create output inward tabular format in addition to nosotros desire to sort based on whatever column. Unix sort command allows us to orbit this past times using sort -k option. Let's come across an instance or Unix sort ascendance to sort the output on whatever column nosotros volition purpose ps ascendance output for this instance in addition to we volition sort this output on column 2 (PID) in addition to afterwards 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 ascendance equally a sort -nk23 volition sort the output root on the minute column in addition to and thus on tertiary column.



4) Sorting output on alphabetical guild past times using UNIX sort command
In this instance of UNIX sort command, nosotros volition come across how to sort the output of whatever ascendance inward alphabetical order. Sort ascendance inward UNIX sorts the output inward alphabetic guild if you lot 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 you lot accept seen inward higher upwards instance of sort ascendance inward UNIX nosotros accept duplicates "stock trading" is coming 2 times. We tin create sorted output without duplicates inward 2 ways inward UNIX either past times passing output of sort ascendance to "uniq" command or past times using sort -u option. Let’s come 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 straightaway on Unix sort command. Please percentage how are you lot using sort ascendance inward Unix , how useful you lot detect UNIX sort ascendance in addition to 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


Belum ada Komentar untuk "5 Example Of Course Ascendance Inwards Unix Or Linux >>>> Unix Tutorial"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel