Help with keep the first record display

Input file:

10 TMP_12 asdg
13 TMP_12 asdg
123 TMP_12 pasf 
123 ASD qwe
224 AW4 asrfwe
524 AW4 2342
724 AW4 poimv
241 AW4 oiljs
.
.

Desired output file:

10 TMP_12 asdg
13 TMP_12 asdg
123 ASD qwe
224 AW4 asrfwe
.
.

Generate desired output file by following criteria:

  1. If column 2 data between two consecutive row are different, print whatever it is;
  2. If column 2 are same but column 3 are different between two consecutive row, print the first record find in particular column 2 data;
  3. If column 2 and column 3 data are exactly the same between two consecutive row, print it out everything in those particular record;

Below is the command I try:

awk '!_[$2]++' infe
10 TMP_12 asdg
123 ASD qwe
224 AW4 asrfwe

Above command can't really handle when face criteria 3 as stated above :frowning:

Thanks for any advice :slight_smile:

This is how far I can get with that terse input sample (and I'm sure I did not understand your clause 2.):

awk     '!_[$2]++
         _[$2] && T[$2,$3]
                                {T[$2,$3]++}
        ' file
10 TMP_12 asdg
13 TMP_12 asdg
123 ASD qwe
224 AW4 asrfwe

Hi RudiC,

Thanks a lot for your suggestion.
Below is the example of Clause 2:

224 AW4 asrfwe
524 AW4 2342
724 AW4 poimv
241 AW4 oiljs

From the above 4 records, they all share the same column 2 data "AW4" but have different column 3 data. For this case, I prefer just keep only the first record.

224 AW4 asrfwe

Hope it makes the thing clear :slight_smile:
Thanks.