5 Illustration Of Assort Ascendency Inwards Unix Or Linux >>>> Unix Tutorial
Friday, August 3, 2018
Add Comment
Sorting is 1 of the essential tasks nosotros ever demand to perform in addition to UNIX or Linux has dandy back upwardly for sorting past times using sort command. No thing what form of trounce script you lot are writing or you lot are looking for about information or reports many times you lot demand to sort the output of 1 ascendance or a laid upwardly of line, amongst a combination of the sort amongst find ascendance and grep inward UNIX you lot tin flaming receive got back upwardly asking in addition to written report quite easily. In this UNIX sort ascendance tutorial, nosotros volition meet how nosotros tin flaming purpose sort ascendance inward UNIX to attain our sorting goal. This tutorial contains about 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 flaming take duplicates in addition to introduce a sorted information inward UNIX.
Now let’s meet what UNIX sort ascendance tin flaming arrive at for us using v examples of UNIX sort commands, I bring 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 allow me know if you lot confront whatever effect piece using these Unix sort examples on whatever other OS. I idea nearly writing on Sort ascendance when I was working on 10 tips to operate fast inward Unix in addition to UNIX ascendance tutorial in addition to Example for beginners exactly somehow I am publishing it quite late. Anyway, straight off you lot bring Some Example of Sort ascendance inward UNIX to sort your files in addition to directory every bit per your need.
Many times instead of alphabetic sorting nosotros demand numeric sorting. Just similar inward below event of Unix sort ascendance if nosotros desire to sort based upon a numeric value of PID nosotros tin flaming purpose sort -n along amongst sort -k(column). Since hither PID is minute column sort -nk2 volition operate for us. This is besides about other dandy event of UNIX sort past times column, which allows you arrive at sort the information based on whatever column inward UNIX.
2) Reverse sort past times using UNIX sort command
Sometimes nosotros demand to sort inward opposite lodge e.g. descending order. sort -r option allows us to perform opposite sorting inward Unix.
3) UNIX sort past times column : Sorting based on whatever column inward the input.
sort ascendance inward Unix to a greater extent than ofttimes than non used inward combination of other Unix commands similar find, grep, ls or ps in addition to most of these commands arrive at output inward tabular format in addition to 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 meet an event or Unix sort ascendance to sort the output on whatever column nosotros volition purpose ps ascendance output for this event in addition to we volition sort this output on column 2 (PID) in addition to after on column iii (PPID)
You tin flaming besides sort based upon multiple columns using sort ascendance every bit a sort -nk23 volition sort the output commencement on the minute column in addition to and thus on tertiary column.
4) Sorting output on alphabetical lodge past times using UNIX sort command
In this event of UNIX sort command, nosotros volition meet how to sort the output of whatever ascendance inward alphabetical order. Sort ascendance inward UNIX sorts the output inward alphabetic lodge if you lot don't render whatever options every bit 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 duplicates from sorted output inward UNIX
As you lot bring seen inward in a higher house event of sort ascendance inward UNIX nosotros bring duplicates "stock trading" is coming ii times. We tin flaming arrive at sorted output without duplicates inward ii ways inward UNIX either past times passing output of sort ascendance to "uniq" command or past times using sort -u option. Let’s meet an event 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
unix-sort-examples@unix-tutorial: /test cat names | sort -u
electronic trading
forex trading
stocks trading
That’s all for straight off on Unix sort command. Please portion 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
Now let’s meet what UNIX sort ascendance tin flaming arrive at for us using v examples of UNIX sort commands, I bring 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 allow me know if you lot confront whatever effect piece using these Unix sort examples on whatever other OS. I idea nearly writing on Sort ascendance when I was working on 10 tips to operate fast inward Unix in addition to UNIX ascendance tutorial in addition to Example for beginners exactly somehow I am publishing it quite late. Anyway, straight off you lot bring Some Example of Sort ascendance inward UNIX to sort your files in addition to directory every bit per your need.
UNIX or Linux Sort Command Examples
1) Sorting based on numeric value of String using UNIX sort command:Many times instead of alphabetic sorting nosotros demand numeric sorting. Just similar inward below event of Unix sort ascendance if nosotros desire to sort based upon a numeric value of PID nosotros tin flaming purpose sort -n along amongst sort -k(column). Since hither PID is minute column sort -nk2 volition operate for us. This is besides about other dandy event 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 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 past times using UNIX sort command
Sometimes nosotros demand to sort inward opposite lodge 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 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 past times column : Sorting based on whatever column inward the input.
sort ascendance inward Unix to a greater extent than ofttimes than non used inward combination of other Unix commands similar find, grep, ls or ps in addition to most of these commands arrive at output inward tabular format in addition to 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 meet an event or Unix sort ascendance to sort the output on whatever column nosotros volition purpose ps ascendance output for this event in addition to we volition sort this output on column 2 (PID) in addition to 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 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 flaming besides sort based upon multiple columns using sort ascendance every bit a sort -nk23 volition sort the output commencement on the minute column in addition to and thus on tertiary column.
4) Sorting output on alphabetical lodge past times using UNIX sort command
In this event of UNIX sort command, nosotros volition meet how to sort the output of whatever ascendance inward alphabetical order. Sort ascendance inward UNIX sorts the output inward alphabetic lodge if you lot don't render whatever options every bit 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 duplicates from sorted output inward UNIX
As you lot bring seen inward in a higher house event of sort ascendance inward UNIX nosotros bring duplicates "stock trading" is coming ii times. We tin flaming arrive at sorted output without duplicates inward ii ways inward UNIX either past times passing output of sort ascendance to "uniq" command or past times using sort -u option. Let’s meet an event 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 straight off on Unix sort command. Please portion 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
0 Response to "5 Illustration Of Assort Ascendency Inwards Unix Or Linux >>>> Unix Tutorial"
Post a Comment