Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sort numerical value using the sort command

Answer:

Assume you have a text file contains the following content:

1
2
3
10

When you use the sort command to sort them, it will give the following output:

# sort test.txt
1
10
2
3

So you need to sort them according to the numerical values?

Try with the n flag:

# sort -n test.txt
1
2
3
10

How to count the number of duplicated lines in a file

Answer:

Assume you have a file "test.txt"

a
b
b
c
c
c

You want to count the number of distinct rows, here is the command

# sort test.txt | uniq -c

1 a
2 b
3 c

How to remove duplicated lines in a file

Answer:

Use the following command

sort test.txt | uniq