Need to delete duplicate lease entry


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to delete duplicate lease entry
# 1  
Old 02-26-2010
Need to delete duplicate lease entry

Hi *,

I need to delete duplicate lease entries in file according to MAC/IP.

I'm having tempfile which contains many lease info and need to have one entry for each IP(not more than that), if it contains more than one entry for same set, need to be deleted that entry...

EX:

Code:
lease 172.19.134.239 {
  starts 3 2010/02/10 04:59:07;
  ends 3 2010/02/10 13:59:07;
  binding state active;
  next binding state free;
  hardware ethernet 00:1d:45:56:b0:e2;
  uid "\000cisco-001d.4556.b0e2-Fa0.14";
  option agent.circuit-id "eth0";
  client-hostname "WAP";
}

Any help is apprciated!!!!

Thanks in Advance

Regards,
SMNK

Last edited by Franklin52; 02-26-2010 at 06:18 AM.. Reason: Please use code tags!
# 2  
Old 02-26-2010
Try:

This will remove duplicates based on IP

Code:
awk '/^lease/ && !A[$2]++ { f=1; } f++<=10' file

input:
Code:
lease 172.19.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.19.134.259 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.15.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
/home/nosadm>cat file
lease 172.19.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.19.134.259 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.15.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.19.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.19.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.15.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}

output:
Code:
lease 172.19.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.19.134.259 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}
lease 172.15.134.239 {
starts 3 2010/02/10 04:59:07;
ends 3 2010/02/10 13:59:07;
binding state active;
next binding state free;
hardware ethernet 00:1d:45:56:b0:e2;
uid "\000cisco-001d.4556.b0e2-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}

# 3  
Old 02-26-2010
MySQL

Hi jacob,

Thanks for your input.....

one more help i need that i have to read the same file(tempfile) and it should be reflected in that file(tempfile) itself(by deleting that entry). i tried someway to overcome the problem

1) tried to overwrite --failed
2) appending---obviously it wont work.

Since am new to scripting......

TIA
# 4  
Old 02-26-2010
No easy way..try something like

Code:
awk '/^lease/ && !A[$2]++ { f=1; } f++<=10 { print >"outfile" }' file
mv outfile file

# 5  
Old 02-26-2010
Thank you verymuch for your immediate responses dennis!!!!!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

2. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

3. Shell Programming and Scripting

Deleting duplicate glosses in a dictionary entry

I am working on an Urdu to Hindi dictionary and I have created the following file structure: Headword=Gloss1,Gloss2,Gloss3 i.e. glosses delimited by a comma. It so happens that in some cases (around 6000+ in a file of over 200,000+ the glosses are duplicated. Since this may be a... (3 Replies)
Discussion started by: gimley
3 Replies

4. UNIX for Dummies Questions & Answers

remove duplicate entries from dhcp.lease

Hi, I have to parse the dhcp.lease file and have to keep the most recent entry and remove the rest and also the number of lines between any two leases might not always be the same. eg: lease 5.5.5.252 { starts Wed Jul 27 09:48:39 2011 ends Wed Jul 27 21:48:39 2011 tstp Wed Jul... (1 Reply)
Discussion started by: bitspradp
1 Replies

5. Shell Programming and Scripting

checking duplicate entry in file

Hi i have a file like 110.10 120.10 -1120 110.10 and the lines are having more than 10k. do we have anycommand to check the duplicate entries in the file. I applied the while loop by greping each line with whole file, but it is taking huge amount of time as the file size is large. ... (5 Replies)
Discussion started by: saluja.deepak
5 Replies

6. UNIX for Dummies Questions & Answers

Compare these two lines and delete the old entry

I have a unique situation here which looks easier at first but I am not able to solve it. # SSort UNIX 10/14/2005 10/13/2010 "tox" "9000/800" 16 * * * V849-6-1 # SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2 I have a text file with two or multiple values like this and... (1 Reply)
Discussion started by: pareshan
1 Replies

7. Shell Programming and Scripting

Print Only second Duplicate entry in the file

I have file where it contains 2 columns. In two columns the first column is repeated more than once. I wanted to take the unique record in first column and the corresponding second column value . The below is the example of the file: 8244100320012955|000b063471a4... (4 Replies)
Discussion started by: ravi_rn
4 Replies

8. Shell Programming and Scripting

delete entry from /etc/hosts file ?

Hi there I have a requirement where i have to globally remove a hosts file entry from all boxes e.g. 10.01.10.1 my_server1 normally for 'in-line' editing of files without passing it out to another fle and copying it back etc which is messy, Ive been using the fantastic "perl -pi... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

9. UNIX for Dummies Questions & Answers

Remove duplicate entry in one line

Can anyone help me how can i print only the unique entry in a line? MI_AP MI_AP MI_CM MI_MF RC_NAP MBS_AP SF_RAN MBS_AP NT_CAR so that it will on output the one unique entry per line. MI_AP MI_CM MI_MF RC_NAP MBS_AP SF_RAN NT_CAR I can't find the same situation on the knowledge... (5 Replies)
Discussion started by: kharen11
5 Replies

10. HP-UX

Hazardous Duplicate Cron Entry?

Hi All, How to prevent starting of processes that have duplicate entries in cron file, i have written a shell script to validate with "ps |grep" command before starting the process, but still when same process started at same time, it may not be able to detect the existing process. Sample... (3 Replies)
Discussion started by: nag_sundaram
3 Replies
Login or Register to Ask a Question