Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 25th April 2008, 06:00
jack777 jack777 is offline
Junior Member
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default remove duplicate lines in a file

Hi
Having a file as follows
Code:
==================================================
Date           Time         error code      server 
======================================================
12-29-08    10:10        121221          server A
12-29-08    10:12        121221          server A
12-29-08    10:10        121221          server B
12-29-08    10:10        121221          server c
Need to remove the duplicate lines with the following conditions

if date=12-29-08 and server=server A .
Must delete the line with old time and keep the latest.

anyone can suggest

Thanks in advance
Reply With Quote
Sponsored Links
  #2  
Old 15th May 2008, 12:24
burschik burschik is offline
Junior Member
 
Join Date: May 2008
Posts: 24
Thanks: 0
Thanked 2 Times in 2 Posts
 
Default Not really duplicate

#!/bin/awk

BEGIN { pattern = /^[[:digit:]]+-[[:digit:]]+-[[:digit:]]/; }

$1 !~ pattern { print; }

$1 ~ pattern {
if ($1 != previous_date && previous_date != "" ||
$5 != previous_server && previous_server != "") {
print previous_line;
}

previous_date = $1;
previous_server = $5;
previous_line = $0;
}

END { print previous_line; }
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
add web site serr57 Installation/Configuration 18 13th April 2008 11:40
Postfix delivery problem erebus Installation/Configuration 6 28th October 2007 16:20
Chroot SSH + ISPConfig Norman Installation/Configuration 27 26th March 2007 03:40
Systemimager (rsync) doesn't copy all comedit HOWTO-Related Questions 11 19th January 2007 17:17
Howto suggestion suse PhP ver 4 + Ver 5 wwparrish Suggest HOWTO 11 7th August 2006 13:29


All times are GMT +2. The time now is 15:56.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.