2
-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.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

No need for cat: sort -nu input
Useless Use of Cat. Otherwise, this is definitely my preferred solution.
I do agree the use of cat is unnecessary here. In this case I was using it as an illustration of getting the data into the sort command. In practice I would advocate simply piping the output of whatever process generates this list into the sort command. I will make that clearer in the future.
4

If you can guarantee the length of the first field,

sort | uniq --check-chars=4 

will do the trick.

Otherwise, try awk:

awk '{ if (FNR == 1 || last != $1) print; last = $1; }'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.