5 Example Of Classify Ascendance Inward Unix Or Linux >>>> Unix Tutorial
Sorting is i of the essential tasks nosotros ever demand to perform in addition to UNIX or Linux has neat back upwards for sorting yesteryear using sort command. No affair what variety of rhythm out script yous are writing or yous are looking for to a greater extent than or less information or reports many times yous demand to sort the output of i dominance or a fix of line, alongside a combination of the sort alongside find dominance and grep inwards UNIX yous tin receive got back upwards asking in addition to written report quite easily. In this UNIX sort dominance tutorial, nosotros volition run into how nosotros tin purpose sort dominance inwards UNIX to accomplish our sorting goal. This tutorial contains to a greater extent than or less of the practical example of sort command for sorting information inwards UNIX. With the purpose of “unique” in addition to “sort” command, yous tin take duplicates in addition to introduce a sorted information inwards UNIX.
Now let’s run into what UNIX sort dominance tin gain 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 plant fine on other OS e.g. Redhat Linux, Solaris or IBM AIX because it's pretty basic command, Please permit me know if yous confront whatsoever effect piece using these Unix sort examples on whatsoever other OS. I idea close writing on Sort dominance when I was working on 10 tips to last fast inwards Unix in addition to UNIX dominance tutorial in addition to Example for beginners merely somehow I am publishing it quite late. Anyway, straight off yous accept Some Example of Sort dominance inwards 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 inwards below instance of Unix sort dominance if nosotros desire to sort based upon a numeric value of PID nosotros tin purpose sort -n along alongside sort -k(column). Since hither PID is minute column sort -nk2 volition last for us. This is besides to a greater extent than or less other neat instance of UNIX sort yesteryear column, which allows you gain sort the information based on whatsoever column inwards UNIX.
2) Reverse sort yesteryear using UNIX sort command
Sometimes nosotros demand to sort inwards contrary fellowship e.g. descending order. sort -r option allows us to perform contrary sorting inwards Unix.
3) UNIX sort yesteryear column : Sorting based on whatsoever column inwards the input.
sort dominance inwards Unix generally used inwards combination of other Unix commands similar find, grep, ls or ps in addition to most of these commands create output inwards tabular format in addition to nosotros desire to sort based on whatsoever column. Unix sort command allows us to gain this yesteryear using sort -k option. Let's run into an instance or Unix sort dominance to sort the output on whatsoever column nosotros volition purpose ps dominance output for this instance in addition to we volition sort this output on column 2 (PID) in addition to afterwards on column three (PPID)
You tin besides sort based upon multiple columns using sort dominance every bit a sort -nk23 volition sort the output starting fourth dimension on the minute column in addition to thence on tertiary column.
4) Sorting output on alphabetical fellowship yesteryear using UNIX sort command
In this instance of UNIX sort command, nosotros volition run into how to sort the output of whatsoever dominance inwards alphabetical order. Sort dominance inwards UNIX sorts the output inwards alphabetic fellowship if yous don't render whatsoever options every bit 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 yous accept seen inwards in a higher house instance of sort dominance inwards UNIX nosotros accept duplicates "stock trading" is coming 2 times. We tin create sorted output without duplicates inwards 2 ways inwards UNIX either yesteryear passing output of sort dominance to "uniq" command or yesteryear using sort -u option. Let’s run into an instance of sorting alongside unique elements using UNIX sort command:
Sorted output alongside 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 yous using sort dominance inwards Unix , how useful yous honor UNIX sort dominance in addition to is in that place 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
Now let’s run into what UNIX sort dominance tin gain 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 plant fine on other OS e.g. Redhat Linux, Solaris or IBM AIX because it's pretty basic command, Please permit me know if yous confront whatsoever effect piece using these Unix sort examples on whatsoever other OS. I idea close writing on Sort dominance when I was working on 10 tips to last fast inwards Unix in addition to UNIX dominance tutorial in addition to Example for beginners merely somehow I am publishing it quite late. Anyway, straight off yous accept Some Example of Sort dominance inwards 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 inwards below instance of Unix sort dominance if nosotros desire to sort based upon a numeric value of PID nosotros tin purpose sort -n along alongside sort -k(column). Since hither PID is minute column sort -nk2 volition last for us. This is besides to a greater extent than or less other neat instance of UNIX sort yesteryear column, which allows you gain 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 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 yesteryear using UNIX sort command
Sometimes nosotros demand to sort inwards contrary fellowship 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 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 yesteryear column : Sorting based on whatsoever column inwards the input.
sort dominance inwards Unix generally used inwards combination of other Unix commands similar find, grep, ls or ps in addition to most of these commands create output inwards tabular format in addition to nosotros desire to sort based on whatsoever column. Unix sort command allows us to gain this yesteryear using sort -k option. Let's run into an instance or Unix sort dominance to sort the output on whatsoever column nosotros volition purpose ps dominance output for this instance in addition to we volition sort this output on column 2 (PID) in addition to afterwards 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 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 besides sort based upon multiple columns using sort dominance every bit a sort -nk23 volition sort the output starting fourth dimension on the minute column in addition to thence on tertiary column.
4) Sorting output on alphabetical fellowship yesteryear using UNIX sort command
In this instance of UNIX sort command, nosotros volition run into how to sort the output of whatsoever dominance inwards alphabetical order. Sort dominance inwards UNIX sorts the output inwards alphabetic fellowship if yous don't render whatsoever options every bit 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 yous accept seen inwards in a higher house instance of sort dominance inwards UNIX nosotros accept duplicates "stock trading" is coming 2 times. We tin create sorted output without duplicates inwards 2 ways inwards UNIX either yesteryear passing output of sort dominance to "uniq" command or yesteryear using sort -u option. Let’s run into an instance of sorting alongside unique elements using UNIX sort command:
Sorted output alongside 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 yous using sort dominance inwards Unix , how useful yous honor UNIX sort dominance in addition to is in that place 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
0 Response to "5 Example Of Classify Ascendance Inward Unix Or Linux >>>> Unix Tutorial"
Post a Comment