5 Illustration Of Assort Ascendence Inwards Unix Or Linux >>>> Unix Tutorial
Sorting is i of the essential tasks nosotros e'er demand to perform together with UNIX or Linux has bang-up 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 closed to information or reports many times you lot demand to sort the output of i ascendence or a fix of line, amongst a combination of the sort amongst find ascendence and grep inward UNIX you lot tin receive got back upwards asking together with study quite easily. In this UNIX sort ascendence tutorial, nosotros volition run into how nosotros tin purpose sort ascendence inward UNIX to attain our sorting goal. This tutorial contains closed to of the practical example of sort command for sorting information inward UNIX. With the purpose of “unique” together with “sort” command, you lot tin withdraw duplicates together with introduce a sorted information inward UNIX.
Now let’s run into what UNIX sort ascendence tin scope for us using five examples of UNIX sort commands, I convey tested these commands on Cygwin running on Windows XP together with I facial expression 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 you lot confront whatever consequence spell using these Unix sort examples on whatever other OS. I idea close writing on Sort ascendence when I was working on 10 tips to operate fast inward Unix together with UNIX ascendence tutorial together with Example for beginners simply somehow I am publishing it quite late. Anyway, forthwith you lot convey Some Example of Sort ascendence inward UNIX to sort your files together with directory equally per your need.
Many times instead of alphabetic sorting nosotros demand numeric sorting. Just similar inward below event of Unix sort ascendence 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 operate for us. This is likewise closed to other bang-up event of UNIX sort past times column, which allows you scope sort the information based on whatever column inward UNIX.
2) Reverse sort past times using UNIX sort command
Sometimes nosotros demand to sort inward contrary gild e.g. descending order. sort -r option allows us to perform contrary sorting inward Unix.
3) UNIX sort past times column : Sorting based on whatever column inward the input.
sort ascendence inward Unix generally used inward combination of other Unix commands similar find, grep, ls or ps together with most of these commands create output inward tabular format together with nosotros desire to sort based on whatever column. Unix sort command allows us to scope this past times using sort -k option. Let's run into an event or Unix sort ascendence to sort the output on whatever column nosotros volition purpose ps ascendence output for this event together with we volition sort this output on column 2 (PID) together with after on column iii (PPID)
You tin likewise sort based upon multiple columns using sort ascendence equally a sort -nk23 volition sort the output source on the minute column together with thus on tertiary column.
4) Sorting output on alphabetical gild past times using UNIX sort command
In this event of UNIX sort command, nosotros volition run into how to sort the output of whatever ascendence inward alphabetical order. Sort ascendence inward UNIX sorts the output inward alphabetic gild 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 withdraw duplicates from sorted output inward UNIX
As you lot convey seen inward higher upwards event of sort ascendence inward UNIX nosotros convey duplicates "stock trading" is coming ii times. We tin create sorted output without duplicates inward ii ways inward UNIX either past times passing output of sort ascendence to "uniq" command or past times using sort -u option. Let’s run into 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 forthwith on Unix sort command. Please percentage how are you lot using sort ascendence inward Unix , how useful you lot honour UNIX sort ascendence together with is at that spot 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 run into what UNIX sort ascendence tin scope for us using five examples of UNIX sort commands, I convey tested these commands on Cygwin running on Windows XP together with I facial expression 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 you lot confront whatever consequence spell using these Unix sort examples on whatever other OS. I idea close writing on Sort ascendence when I was working on 10 tips to operate fast inward Unix together with UNIX ascendence tutorial together with Example for beginners simply somehow I am publishing it quite late. Anyway, forthwith you lot convey Some Example of Sort ascendence inward UNIX to sort your files together with directory equally 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 ascendence 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 operate for us. This is likewise closed to other bang-up event of UNIX sort past times column, which allows you scope 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 gild 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 ascendence inward Unix generally used inward combination of other Unix commands similar find, grep, ls or ps together with most of these commands create output inward tabular format together with nosotros desire to sort based on whatever column. Unix sort command allows us to scope this past times using sort -k option. Let's run into an event or Unix sort ascendence to sort the output on whatever column nosotros volition purpose ps ascendence output for this event together with we volition sort this output on column 2 (PID) together with 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 ascendence equally a sort -nk23 volition sort the output source on the minute column together with thus on tertiary column.
4) Sorting output on alphabetical gild past times using UNIX sort command
In this event of UNIX sort command, nosotros volition run into how to sort the output of whatever ascendence inward alphabetical order. Sort ascendence inward UNIX sorts the output inward alphabetic gild 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 withdraw duplicates from sorted output inward UNIX
As you lot convey seen inward higher upwards event of sort ascendence inward UNIX nosotros convey duplicates "stock trading" is coming ii times. We tin create sorted output without duplicates inward ii ways inward UNIX either past times passing output of sort ascendence to "uniq" command or past times using sort -u option. Let’s run into 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 forthwith on Unix sort command. Please percentage how are you lot using sort ascendence inward Unix , how useful you lot honour UNIX sort ascendence together with is at that spot 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 Ascendence Inwards Unix Or Linux >>>> Unix Tutorial"
Post a Comment