5 Event Of Course Of Teaching Ascendance Inwards Unix Or Linux >>>> Unix Tutorial

Advertisement

Masukkan script iklan 970x90px

5 Event Of Course Of Teaching Ascendance Inwards Unix Or Linux >>>> Unix Tutorial

Rabu, 30 Desember 2020

Sorting is ane of the essential tasks nosotros e'er demand to perform in addition to UNIX or Linux has keen back upwards for sorting yesteryear using sort command. No thing what form of musical rhythm out script y'all are writing or y'all are looking for approximately information or reports many times y'all demand to sort the output of ane ascendence or a laid upwards of line, amongst a combination of the sort amongst find ascendence and grep inwards UNIX y'all tin grip back upwards asking in addition to written report quite easily. In this UNIX sort ascendence tutorial, nosotros volition encounter how nosotros tin role sort ascendence inwards UNIX to grade our sorting goal. This tutorial contains approximately of the practical example of sort command for sorting information inwards UNIX. With the role of “unique” in addition to “sort” command, y'all tin take duplicates in addition to introduce a sorted information inwards UNIX.

Now let’s encounter what UNIX sort ascendence tin arrive at for us using five examples of UNIX sort commands, I convey tested these commands on Cygwin running on Windows XP in addition to I await it industrial plant fine on other OS e.g. Redhat Linux, Solaris or IBM AIX because it's pretty basic command, Please permit me know if y'all human face upwards whatsoever effect piece using these Unix sort examples on whatsoever other OS. I idea almost writing on Sort ascendence when I was working on 10 tips to hold upwards fast inwards Unix in addition to UNIX ascendence tutorial in addition to Example for beginners only somehow I am publishing it quite late. Anyway, straightaway y'all convey Some Example of Sort ascendence inwards 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 ascendence inwards UNIX or Linux   >>>>  Unix TutorialMany times instead of alphabetic sorting nosotros demand numeric sorting. Just similar inwards below instance of Unix sort ascendence if nosotros desire to sort based upon a numeric value of PID nosotros tin role sort -n along amongst sort -k(column). Since hither PID is minute column sort -nk2 volition hold upwards for us. This is besides approximately other keen instance of UNIX sort yesteryear column, which allows you arrive at sort the information based on whatsoever column inwards UNIX.


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




2) Reverse sort yesteryear using UNIX sort command
Sometimes nosotros demand to sort inwards contrary lodge e.g. descending order. sort -r option allows us to perform contrary sorting inwards 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 eighteen /usr/bin/bash
unix-sort-examples    3448       0   0    Jan  1 /usr/bin/ps
unix-sort-examples    3332    2676   1    Jul eighteen /usr/bin/bash
unix-sort-examples     500    2832   0    Jul eighteen /usr/bin/bash
     UID     PID    PPID TTY     STIME COMMAND



3) UNIX sort yesteryear column : Sorting based on whatsoever column inwards the input.
sort ascendence inwards Unix to a greater extent than ofttimes than non used inwards combination of other Unix commands similar find, grep, ls or ps in addition to most of these commands arrive at output inwards tabular format in addition to nosotros desire to sort based on whatsoever column. Unix sort command allows us to arrive at this yesteryear using sort -k option. Let's encounter an instance or Unix sort ascendence to sort the output on whatsoever column nosotros volition role ps ascendence output for this instance in addition to we volition sort this output on column 2 (PID) in addition to afterward on column three (PPID)

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

You tin besides sort based upon multiple columns using sort ascendence equally a sort -nk23 volition sort the output starting fourth dimension on the minute column in addition to and hence on tertiary column.



4) Sorting output on alphabetical lodge yesteryear using UNIX sort command
In this instance of UNIX sort command, nosotros volition encounter how to sort the output of whatsoever ascendence inwards alphabetical order. Sort ascendence inwards UNIX sorts the output inwards alphabetic lodge if y'all don't render whatsoever options equally shown inwards 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 duplicates from sorted output inwards UNIX
As y'all convey seen inwards to a higher house instance of sort ascendence inwards UNIX nosotros convey duplicates "stock trading" is coming 2 times. We tin arrive at sorted output without duplicates inwards 2 ways inwards UNIX either yesteryear passing output of sort ascendence to "uniq" command or yesteryear using sort -u option. Let’s encounter 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 part how are y'all using sort ascendence inwards Unix , how useful y'all uncovering UNIX sort ascendence in addition to is at that topographic point whatsoever other alternative of Unix sort inwards other OS e.g. Redhat Linux, Solaris or IBM AIX ?

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