SMNK
February 26, 2010, 3:11am
1
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:
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
Try:
This will remove duplicates based on IP
awk '/^lease/ && !A[$2]++ { f=1; } f++<=10' file
input:
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:
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";
}
SMNK
February 26, 2010, 5:15am
3
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
No easy way..try something like
awk '/^lease/ && !A[$2]++ { f=1; } f++<=10 { print >"outfile" }' file
mv outfile file
SMNK
February 26, 2010, 8:23am
5
Thank you verymuch for your immediate responses dennis!!!!!