I have a log file that may have the following lines among 100 other lines
hosta: Info: Tue Nov 25  19:44:39 2014>
User jwayman at position 170.198.3.141 disconnected 
hosta: Info: Tue Nov 23  19:44:39 2014>
User jho at position 170.198.3.141 disconnected 
hosta: Info: Tue Nov 26  19:44:39 2014>
User jho at position 170.198.3.141 disconnected 
I need to look for occurrences of "disconnected" and then if the date ( from the line above it ) matches the today's date then I want to print the following information:
user jho disconnected from server "hosta"
So I need to pull data from both lines and then do something with it.
I was thinking of doing this in a array and assign all occurrences to variables in array.
But I hope that someone can introduce an easier way of doing this, maybe with a grep and awk.
                        
You can use the following:
Explanation
$(date "+%a %b %d")returns on the formatWed Nov 26.$3 FS $4 FS $5 == today {f=1; next}checks is the current line has this format. If so, a flagfis activated.f && /disconnected/ {print}if the flag is set and the line containsdisconnected, then prints it.f=0unsets the flag.Test
Sample file:
Check the script: