Linux uniq command with options and descriptions

The uniq command you can form a sorted list in which every word will occur only once.

Sample syntax of uniq command :

# command <filename> | uniq

Like example of uniq command :

# sort test | uniq

See your terminal after run the command, words which are repeating, repeats only once with the ‘uniq’ command.

uniq -c command

You can count the number of occurrences of a word with ‘uniq -c’ command.

Sample syntax of uniq-c command :

# command <file name> | uniq -c

Like example of uniq command :

# sort test | uniq -c

See your terminal after run the command, command “sort test | uniq -c” counts the number of times a word is repeating.

Linux wc command

wc command helps in counting the lines, words and characters in a file.

Sample syntax of wc command :

# wc <fileName>     (Counts words, lines and characters)  
# wc -l <fileName>      (Counts only lines)  
# wc -w <fileName>      (Counts only words)  
# wc -c <fileName>      (Counts only characters)  

Like example of wc command :

# wc exm.txt  
# wc -l exm.txt  
# wc -w exm.txt  
# wc -c exm.txt

See your terminal after run the command, command “wc test” displays all three counts together, command wc -l test displays line counts, command “wc -w test” displays word counts and command “wc -c test” displays character counts.

Linux od command

od term stands for octal dump. It displays content of a file in different human-readable formats like hexadecimal, octal and ASCII characters.

Sample syntax of od command :

# od -b <fileName>      (display files in octal format)  
# od -t x1 <fileName>       (display files in hexadecimal bytes format)  
# od -c <fileName>      (display files in ASCII (backslashed) character format)  

Like example of od command :

# od -b format.txt                            
# od -t x1 format.txt  
# od -c format.txt  

See your terminal after run the command, command “od -b format.txt” displays in octal format, command “od -t x1 format.txt” displays in hexadecimal format, command “od -c format.txt” displays in ASCII character where a new line will be marked with ‘\n’

Linux sort command

The Linux or Unix sort command sorts the file content in an alphabetical order.

Sample syntax of sort command :

# sort <file name>

Like example of sort command :

# sort test

See your terminal after run the command, the ‘sort’ command has sorted the file ‘weeks.txt’ in alphabetical order

To Sort A Column

If a file has more than one column, column number is used to sort a specific column.

Sample syntax of sort A command :

# sort -k <column number> <file name>

Like example of sort A command :

# sort -k1 test  
# ort -k2 test  

See your terminal after run the command, we have sorted column 1 and 2.

Numeric Sorting

Numeric sorting is different from alphabetical sorting.

n is used for numerical sorting along with the column number if required.

Sample syntax of sort -n -k command :

# sort -n -k <columm number> <file name>

Like example of sort -n -k command :

# sort -n -k2 test

After run command on your terminal then you can see all of the benefits both command.

Leave a Reply