getting data out from a text file

Hi
Is it possible for me to extract particular lines from the text lines below. For example I want to extract the first three lines and the 4 lines below <owner>. I ant to put them in one line like thus:
12.33.164.12 UNITED HEALTHCARE CORP. 6300 OLSEN MEMORIAL HIGHWAY GOLDEN VALLEY, MN 55427 US

I have a file full of data like this and would like to create rows with jsut the IP address and the owner.

Can you please help!!

<ip address/hostname>
12.33.164.12
uhgatt12.uhc.com

<net block>
12.33.164.0 - 12.33.164.15

<owner>
UNITED HEALTHCARE CORP.
6300 OLSEN MEMORIAL HIGHWAY
GOLDEN VALLEY, MN 55427
US

<administrative contact>
Elverhoy, Dave dehoy@uhc.com
(612)797-2113

<additional data>
UNITED-164-0
Updated: 28-Jun-2000
Source: rs1.arin.net

sounds like your trying to build your own version of a whois record for some sort of program that logs ip addys of hosts you have "tested" for something.

i think i wont touch this one. but i will point you in teh right direction.

why dont you check out a book by oreilly its called "Mastering Regulard Expressions 2nd edition"

Either that, or for spam...

you are right in that I am trying to use the output of an whois report. Thanks for pointing me in the right direction with this. Let me assure you... this is not for spamming. I am jsut getting the output in a tabular manner.

I will check out the O'Reily book... thank you!

well, if you are using Perl, i think you can easily retrieve those information by using "split" and also "=~" commands to search for the right kind of data that you wish to retrieve.
i have once done this to retrieve the information displayed on the screen by the iptables,
first i saved the screen in a file and then i split them up into pieces for easy lookup. last but not least i use the "=~" commands to look for the right words.

=~ is not a command it is an operator. to be more specific its a binding operator to tie a scalar value to a pattern matching expression which will be on the right side of the operator.

Am I good or just bored?:o

don't answer that.

#!/usr/local/bin/perl
#by photon
#

$file = 'data.txt' ;
open(INFO, "$file" ) ;
@lines = <INFO> ;
close(INFO) ;


$count = 0;

foreach $line (@lines){

        if ($line =~ m/\<ip address\/hostname\>/){
                $count = 1;
        }elsif($line =~ m/\<owner\>/){
                $count = 2;
        }elsif($count == 1){
                push(@data, $line);
                print "$line \n";
                $count = 0;
        }elsif($count == 2){
                 if ($line !~ m/\<administrative contact\>/ ){
                         push(@data, $line);
                         print "$line \n";
                 }else{
                         $count = 0;
                  }
         }else{ # Reset count
                 $count = 0;
         }
}

open ( REPORT_FILE, ">report.txt" ) || die " report.txt $! \n " ;

foreach $data (@data){

format REPORT_FILE =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$data
.
write REPORT_FILE ;
}
print "\nSee report.txt\nALL DONE\n\n" ;
awk '\
$0~"<ip address/hostname>" {\
   getline; printf $0 " "}
$0~"<owner>" {\
   getline; printf $0 " "
   getline; printf $0 " "
   getline; printf $0 " "
   getline; print
}' skotapal.data