Question: I have a data file consists of several rows and columns with numeric and string data. Some string and numeric patterns are repeated. I need to extract last repeated pattern. For example;

```
715 ANKR PRN 1 value 1
760 ISTA PRN 2 value 2
715 ANKR PRN 1 value 3
760 ISTA PRN 2 value 4
715 ANKR PRN 1 value 5
760 ISTA PRN 2 value 6
  1 ANKR PRN 7 value 8
  2 ISTA PRN 7 value 9
  1 ANKR PRN 7 value 10
  3 ISTA PRN 7 value 11
  1 ANKR PRN 7 value 12

```

in this example "715 ANKR PRN 1", "760 ISTA PRN 2" and "1 ANKR PRN 7"are repeated 3 times within the data file. I need to extract last repeated patterns and sort as follows;

```
715 ANKR PRN 1 value 5
760 ISTA PRN 2 value 6
  1 ANKR PRN 7 value 12

```

Answer: 
Using standard tools, `sort`, `rev`, `uniq`:

```
% sort -k1,5 -k6,6nr file.txt | rev | uniq -f1 -d | rev

  1 ANKR PRN 7 value 12
715 ANKR PRN 1 value 5
760 ISTA PRN 2 value 6

```

If you want sort the output as desired:

```
% sort -k1,5 -k6,6nr file.txt | rev | uniq -f1 -d | rev | sort -k6,6n

715 ANKR PRN 1 value 5
760 ISTA PRN 2 value 6
  1 ANKR PRN 7 value 12

```
How about

```
awk '{a[$1 FS $2 FS $3 FS $4 FS $5] = $6; c[$1 FS $2 FS $3 FS $4 FS $5]++}; END{for (i in a) {if (c[i]>1) print i,a[i]}}'

```

Testing with your input

```
$ awk '{a[$1 FS $2 FS $3 FS $4 FS $5] = $6; c[$1 FS $2 FS $3 FS $4 FS $5]++}; END{for (i in a) {if (c[i]>1) print i,a[i]}}' file
715 ANKR PRN 1 value 5
760 ISTA PRN 2 value 6
1 ANKR PRN 7 value 12

```