The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing lines that are (same in content) based on columns adsforall UNIX for Dummies Questions & Answers 7 11-09-2007 08:13 AM
remove duplicated lines without sort lalelle Shell Programming and Scripting 6 08-21-2007 04:44 AM
Error when find and remove directory based on time HAA Shell Programming and Scripting 1 02-01-2007 11:56 PM
Remove lines with n columns Krispy Shell Programming and Scripting 2 11-10-2006 01:41 AM
Sort by Columns murbina UNIX for Dummies Questions & Answers 1 05-10-2004 11:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2008
karthikn7974's Avatar
Supporter
 

Join Date: Jul 2007
Location: Singapore
Posts: 53
Remove lines, Sorted with Time based columns using AWK & SORT

Hi

having a file as follows

MediaErr.log
Code:
84   Server1     Policy1       Schedule1 master1   05/08/2008 02:12:16
84   Server1     Policy1       Schedule1 master1   05/08/2008 02:22:47
84   Server1     Policy1       Schedule1 master1   05/08/2008 03:41:26
84   Server1     Policy1       Schedule1 master1   05/08/2008 03:42:26
using below command to print duplicate line with latest time
Code:
nawk '!arr[$1]++ || arr[$3]++ || arr[$7]>=1' MediaErr.log
Current Output
Code:
84   Server1     Policy1       Schedule1 master1   05/08/2008 02:12:16
84   Server1     Policy1       Schedule1 master1   05/08/2008 03:42:26
but could not get exact output

it should be
Code:
84   Server1     Policy1       Schedule1 master1   05/08/2008 02:22:47
84   Server1     Policy1       Schedule1 master1   05/08/2008 03:42:26
any suggestions
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-09-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 176
I guess you're looking for the most recent timestamp within an hour for your log file (?).

If sorting is not an issue use:

Code:
 
awk '{split($NF,a,":"); b[a[1]]=$0}END{for (i in b) print b[i]}' MediaErr.log
Otherwise sort your file first:

Code:
sort -k 7.1,7.2n -k 7.4,7.5n -k 7.7,7.8n  MediaErr.log | awk '{split($NF,a,":"); b[a[1]]=$0}END{for (i in b) print b[i]}'

Last edited by rubin; 05-10-2008 at 09:58 PM. Reason: typo, replaced sort keys 7.6,7.7 --> 7.7,7.8 in the last code.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0