0

I have a file with a patter like this:

1 1 1 2 0 1 0.5
1 2 2 2 0 2 0.5
2 1 1 1 0 1 0.25
2 1 2 2 0 2 0.5
2 3 3 3 0 3 0.25

I want to remove a line if another line in the file has the same last two entries. In the example above this means that line 4 should be removed:

1 1 1 2 0 1 0.5
1 2 2 2 0 2 0.5
2 1 1 1 0 1 0.25
2 3 3 3 0 3 0.25

I can't get my head around how I can do this via the command line or with a simple awk/sed script. Any help is greatly appreciated!

Aplln
  • 45
  • 6

2 Answers2

3
awk '!a[$NF,$(NF-1)]++' file

Make an array and check it hasn't already been populated with the last two fields.

123
  • 10,778
  • 2
  • 22
  • 45
1

try:

 sort -k 6 f1.txt  | uniq -f 5

assuming the original order of the lines doesn't matters.

pasaba por aqui
  • 3,446
  • 16
  • 40