Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 02-18-2008, 01:06 PM   #1
Registered: Feb 2008
Posts: 84

Rep: Reputation: 16
Extract substring matching a regular expression


I would like to extract all IP addresses from a html file and assign them to an variable for further processsing.

The lines in file look like this:

[HTML]<li><a href=file.php></a></li>[/HTML]

I don't know how to use the regular expression together with sed or awk to work properly. I only found examples for string replacing but not for extracting.

Thanks very much.
Old 02-18-2008, 01:26 PM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,840

Rep: Reputation: 342Reputation: 342Reputation: 342Reputation: 342
Have you considered using Writer? Open the file in Writer, then go to Tools - Macros - Record Macro.

Go though the steps with mouse and keyboard of selecting the first three or four URLs to extablish a pattern of actions. Stop recording and save the macro.

Then edit the macro to try to make it work on the entire file. Writer uses either sbasic or starbasic, which is much like microsoft's visual basic.
Old 02-18-2008, 01:47 PM   #3
Registered: Feb 2008
Posts: 84

Original Poster
Rep: Reputation: 16
I did not write it above. I want to use a bash script to do that.

I tried something like: ip_address=`expr "$line" : '(\d{1,3}\.){3}\d{1,3}'` but it does not work.

Last edited by tikit; 02-19-2008 at 01:00 PM.


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
extract substring from string in C baddah Programming 6 02-02-2010 04:22 AM
bourne shell pattern matching or regular expression powah Programming 2 06-30-2006 10:27 AM
Rular expression matching with java linuxmandrake Programming 2 04-13-2006 11:35 AM
regular expression matching linuxmandrake Programming 2 03-16-2006 06:00 AM

All times are GMT -5. The time now is 05:08 PM.

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