Skip to main content
2 of 4
added 243 characters in body
terdon
  • 252.2k
  • 69
  • 480
  • 718

Here's another awk approach:

 tac file | awk -F, '{if($1!=last){print;}last=$1}' | tac

The -F, sets the delimiter. Then, for each line, we print it if its first field is not the same as the current value of last. Then, for each line, the last variable is set to the first field. This will leave the original order unchanged.

Since the script above will keep the first and not the last of each run of duplicates, the two tac calls are an ugly hack to reverse the order and make it keep the last. Since there are two, the final order will be unchanged.

terdon
  • 252.2k
  • 69
  • 480
  • 718