Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sort these values using Bash Script in Linux?

-53 45
-54 43
-55 42
-56 41
-57 40
-59 37
-61 35
-61 36
-62 34
-64 33
-65 31
-65 32
-67 30
-68 29
-69 28
-72 25
-73 23
-73 24
-74 22
-76 20
-76 22
-78 20
-79 18
-80 17
-81 16

In the above you will see that at -61 occurs twice and so do some other values. I want to just create a new file without any duplicates. So the new file should have either -61 35 or -61 36 ...

How do I do that?! I tried using sort using uniq but that didn't work.

like image 238
maths Avatar asked Feb 19 '26 00:02

maths


1 Answers

Assuming your data is in a file called input

cat input | sort -u -n

When doing a numeric (-n) sort along with unique (-u), the duplicate checking is achieved.

like image 179
Mike Clark Avatar answered Feb 21 '26 13:02

Mike Clark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!