#!/usr/bin/env awk -f
#
#  uniq-k1 - mimic the behavior of the Unix sort(1) command, "sort -u -k1,1"
#
#  purpose:
#     To imitate the operation of uniq, on first field only. It
#     mimics the behavior of the Unix command, "sort -u -k1,1".
#
#  This script is not useful in itself, but suggests how to delete
#  duplicate records or duplicate sets of data in different contexts.
#
#  Input files must already be sorted on 1st field. If the 1st field
#  of two consecutive lines match, discard the top line. Resume the
#  comparison with the next line. If the 1st field of two consecutive
#  lines do NOT match, print the top line and loop.
#
#  Syntax:  sort -switches input.file | awk -f uniq-1.awk

# set field separator to a blank space
BEGIN {
    FS = " "
}

{
    # If 1st field != previous var and if
    if (var != $1 && NR != 1) {
        # the record number != 1, print line.
        print line
        # For each line, set 'var' to field #1
   }
   var = $1
   # For each line, set 'line' variable.
   line = $0
}

# Print last line in buffer!
END {
    print line
}
