LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Assistance with extracting a series of lines from a log file (https://www.linuxquestions.org/questions/linux-general-1/assistance-with-extracting-a-series-of-lines-from-a-log-file-335908/)

katsal 06-21-2005 06:40 PM

Assistance with extracting a series of lines from a log file
 
Hi People.

I have an interesting question that is sort of bugging me.

We have a dhcp leases file that contains entries similar to the below file.
Now what I would like to do is perform a quick grep on a value, in this case an IP address, and have return to me everything belonging to that IP address. ie....everything from the opening brackets to the closing brackets ({, }).

As most will be aware, a grep on an IP address, will only return the line that the ip address is on.

If anyone knows of a command, or how to create a simple script that extracts the requested information, and can help....That would be really appreciated.

========================
}
lease X.X.X.X{
starts 3 2005/06/;
ends 3 2005/06/;
tstp 6 2005/06/;
cltt 3 2005/06/;
binding state free;
hardware ethernet XXXXXXXXXXX;
}
lease X.X.X.X{
starts 3 2005/06/;
ends 3 2005/06/;
tstp 6 2005/06/;
cltt 3 2005/06/;
binding state free;
hardware ethernet XXXXXXXXXXX;
}
========================

Thanks in advance.

Tinkster 06-21-2005 06:55 PM

awk 'BEGIN{RS="lease"; FS="{"} $1 ~ /X.X.X.X/ {print $0}' lease.txt


Cheers,
Tink


All times are GMT -5. The time now is 10:54 PM.