sort command in linux

sort commandThe sort command arranges lines of text alphabetically or numerically in order.

Output of file

# cat file1
3
4
5
2
1

Use sort command to arrange value in order

# sort file1
1
2
3
4
5

Redirect out of sort command in new file

#  sort file1 > sortoutput

# cat sortoutput
1
2
3
4
5

Arrange value in reverse order

# sort -r file1
5
4
3
2
1

Remove duplicate value from file and arrange in ascending order
File output
# cat newfile
5
4
3
3
2
2
1

#sort -u newfile
1
2
3
4
5

sort command, Marge two file
File2 output, as file1 output mentioned above

# cat file2
4
2
5
6

# sort file1 file2
1
2
2
3
4
4
5
5
6

sort command, Marge two file and remove duplicate entry

# sort -u file1 file2
1
2
3
4
5
6