Skip to main content
2 of 3
added 43 characters in body
user53029
  • 3k
  • 10
  • 46
  • 70

Print only unique lines that appear last in logfile based on date/time

I'm working with a logfile with the following format:

Oct 12 01:28:26 server program: 192.168.1.105 more text here
Oct 12 01:30:00 server program: 192.168.1.104 more text here
Oct 12 01:30:23 server program: 192.168.1.103 more text here
Oct 12 01:32:39 server program: 192.168.1.101 more text here
Oct 12 02:28:26 server program: 192.168.1.105 more text here
Oct 12 02:30:00 server program: 192.168.1.104 more text here
Oct 12 02:30:23 server program: 192.168.1.103 more text here
Oct 12 02:32:39 server program: 192.168.1.101 more text here

I need to achieve this:

Oct 12 02:28:26 server program: 192.168.1.105 more text here
Oct 12 02:30:00 server program: 192.168.1.104 more text here
Oct 12 02:30:23 server program: 192.168.1.103 more text here
Oct 12 02:32:39 server program: 192.168.1.101 more text here

How can I send the new output to a file? I have tried this:

awk '!_[$6]++ {a=$6} END{print a}' logfile

But it does not give me the results expected. How can I use awk or sed to give me only the unique lines with last time the string match was seen or based on date/time?

user53029
  • 3k
  • 10
  • 46
  • 70