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. |
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. |