sort uniq
sort us -rnk1
reverse sorting for 1 column
Sorted output without duplicates
cat names | sort | uniq
-------------------
bash-3.00# sort -n s.txt
1.Apple
2.Orange
3.TOmato
4.Potatoes
5.Carrot
bash-3.00# sort -r s.txt
5.Carrot
4.Potatoes
3.TOmato
2.Orange
1.Apple
bash-3.00# cat s.txt
1.Apple
2.Orange
3.TOmato
4.Potatoes
5.Carrot
1.Applie
2.Orange
5.Carrot
bash-3.00# sort s.txt | uniq
1.Apple
1.Applie
2.Orange
3.TOmato
4.Potatoes
5.Carrot
bash-3.00# sort s.txt | uniq -u
1.Apple
1.Applie
3.TOmato
4.Potatoes
----------------
sort file1 | uniq -d
найти 2 одинаковые строки
----------------------
$ cat happybirthday.txt
Happy Birthday to You!
Happy Birthday to You!
Happy Birthday Dear Tux!
Happy Birthday to You!
$ sort happybirthday.txt
Happy Birthday Dear Tux!
Happy Birthday to You!
Happy Birthday to You!
Happy Birthday to You!
$ sort happybirthday.txt | uniq
Happy Birthday Dear Tux!
Happy Birthday to You!
$ sort happybirthday.txt | uniq -u
Happy Birthday Dear Tux!
$ sort happybirthday.txt | uniq -d
Happy Birthday to You!
uniq is to be used always along with the sort command using pipe or using a sorted file as input
Comments
Post a Comment