LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 06-21-2005, 06:40 PM   #1
katsal
LQ Newbie
 
Registered: Aug 2003
Location: Australia
Distribution: Red Hat Linux
Posts: 7

Rep: Reputation: 0
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.
 
Old 06-21-2005, 06:55 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

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


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to extract certain lines from a log file Avatar Linux - Newbie 3 02-11-2005 09:51 AM
extracting gz file..... b123coder Linux - Newbie 1 11-21-2004 07:55 AM
/etc/securetty --> I commented out all lines and I can still log in as root adamrau Linux - Security 2 05-30-2004 06:16 AM
Extracting Lines from files supreme_command Linux - Newbie 1 05-12-2004 04:21 AM
extracting this file... Xylicon Linux - General 4 01-23-2003 08:49 AM


All times are GMT -5. The time now is 05:02 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration