LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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
  Search this Thread
Old 07-11-2004, 08:43 AM   #1
selfsck
LQ Newbie
 
Registered: Dec 2003
Distribution: FreeBSD / Redhat
Posts: 9

Rep: Reputation: 0
Grep parsing issue


i'm trying to extract ip's and port numbers from a html file but the task ended up being more complicated the what i had expected, here is a sample from file:

<td class=xl27 x:num="38178">2004-7-10</td>
<td height=19 class=xl25 style='height:14.25pt'>80.110.116.179</td>
<td class=xl25>5561</td>


i need to isolate "80.110.116.179" as well as "5561" ( 0-65535) and place it on the same line ( xxx.xxx.xxx.xxx pN). I tought about using awk with "> <" delimiter without any luck, can't "cut" the output since some ip's are longer than others, grep '[0-9]\{3\}.[0-9]\{3\}. [0-9]\{3\}' turn out giving too many jusk data...there must be a simple way to accomplish this task that i am not seeing... any CLI wiz up for a challenge ?


thanks for your time
________________
Selfsck
 
Old 07-11-2004, 11:34 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
Using egrep, this reg exp will grep all lines with legal ip numbers only (0.0.0.0 - 255.255.255.255):

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

Now you should be able to pipe it thru awk to cut it:

awk -F"[<>]" '{ print $3}'

This only works if the number of <'s and >'s in front of the ip number are the same for all the ip lines (and the closing < should be there, too).

Hope this gets you going again.
 
Old 07-11-2004, 07:26 PM   #3
selfsck
LQ Newbie
 
Registered: Dec 2003
Distribution: FreeBSD / Redhat
Posts: 9

Original Poster
Rep: Reputation: 0
i get " Badly placed (. " error message from the command, ill try to
play with the syntax a little.. beside, i still haven't found a way to
display both ip's and port nunbers on the same line...hmm wonders
 
Old 07-11-2004, 08:38 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
You don't show the command you tried, it should be something like this:

egrep 'expression' <file>

There should be single (or double) quotes around the expression.

Displaying 2 (or more) items on the same line can be done in various ways, here's just one:

- Fill 2 (or more) variables:
THIS="`grep 'foo' somefile | cut -d: -f2`"
THAT="`egrep 'bar' otherfile | awk '{ print $3}'`"

and print/echo these:
echo $THIS $THAT
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep issue of escaping backticks in perl rajatgarg Programming 2 05-27-2004 01:27 AM
Shell grep issue philipz Programming 8 05-05-2004 01:50 PM
"grep: /etc/issue: No such file or directory" hunter_one Linux - Software 6 10-15-2003 03:27 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM
grep -v issue lleemon Linux - General 7 06-16-2003 03:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:41 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration