Skip to main content
added 12 characters in body
Source Link
user53029
  • 3k
  • 10
  • 46
  • 70

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

Oct 12 01:28:26 server program: 192.168.1.105 more text herefor 1.105 
Oct 12 01:30:00 server program: 192.168.1.104 more text herefor 1.104 
Oct 12 01:30:23 server program: 192.168.1.103 more text herefor 1.103
Oct 12 01:32:39 server program: 192.168.1.101 more text herefor 1.101 
Oct 12 02:28:26 server program: 192.168.1.105 more text herefor 1.105 
Oct 12 02:30:00 server program: 192.168.1.104 more text herefor 1.104
Oct 12 02:30:23 server program: 192.168.1.103 more text herefor 1.103 
Oct 12 02:32:39 server program: 192.168.1.101 more text herefor 1.101 

I need to achieve this:

Oct 12 02:28:26 server program: 192.168.1.105 more text herefor 1.105 
Oct 12 02:30:00 server program: 192.168.1.104 more text herefor 1.104
Oct 12 02:30:23 server program: 192.168.1.103 more text herefor 1.103
Oct 12 02:32:39 server program: 192.168.1.101 more text herefor 1.101

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?

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?

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

Oct 12 01:28:26 server program: 192.168.1.105 text for 1.105 
Oct 12 01:30:00 server program: 192.168.1.104 text for 1.104 
Oct 12 01:30:23 server program: 192.168.1.103 text for 1.103
Oct 12 01:32:39 server program: 192.168.1.101 text for 1.101 
Oct 12 02:28:26 server program: 192.168.1.105 text for 1.105 
Oct 12 02:30:00 server program: 192.168.1.104 text for 1.104
Oct 12 02:30:23 server program: 192.168.1.103 text for 1.103 
Oct 12 02:32:39 server program: 192.168.1.101 text for 1.101 

I need to achieve this:

Oct 12 02:28:26 server program: 192.168.1.105 text for 1.105 
Oct 12 02:30:00 server program: 192.168.1.104 text for 1.104
Oct 12 02:30:23 server program: 192.168.1.103 text for 1.103
Oct 12 02:32:39 server program: 192.168.1.101 text for 1.101

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?

added 43 characters in body
Source Link
user53029
  • 3k
  • 10
  • 46
  • 70

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?

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 seen?

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?

Source Link
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 seen?