Here's another option that will generate your desired results:
use Modern::Perl;
use Sort::Key::IPv4 qw(ipv4sort);
my %hash;
do {
chomp( my ( $ip, $fld2, $fld3 ) = ( split /\t/ )[ 1 .. 3 ] );
push @{ $hash{$ip} }, "$fld2=$fld3";
}
for <DATA>;
print "$_|" . join( '|', @{ $hash{$_} } ) . "\n\n" for ipv4sort keys %
+hash;
__DATA__
9885 10.10.9.48 Room 1105A
9885 10.10.9.48 Jack 1105A--05D
9885 10.10.9.48 org_code B703
9885 10.10.9.48 Building 1268A
114948 10.10.184.0 nasa_nets off
114948 10.10.184.0 blockSecName test name
114948 10.10.184.0 blockTechName brian test
114948 10.10.184.0 blockAdminName test admin
114949 10.10.184.0 blockSecName John G. Smooth
114949 10.10.184.0 blockTechPhone 256-555-1212
114949 10.10.184.0 blockAdminName Lucy P. Wallice
114949 10.10.184.0 blockAdminId 8878787
114949 10.10.184.0 block_name unknown
114949 10.10.184.0 blockSecId 787878
114949 10.10.184.0 blockAdminEmail lucy.p.wallice@nasa.gov
114949 10.10.184.0 blockTechName TEST LAN
114949 10.10.184.0 blockSecPhone 256-555-3232
114949 10.10.184.0 blockTechEmail terCInternal@mail.nasa.gov
114949 10.10.184.0 blockSecEmail John.goody@nasa.gov
114949 10.10.184.0 nasa_nets Soff
Output:
10.10.9.48|Room=1105A|Jack=1105A--05D|org_code=B703|Building=1268A
10.10.184.0|nasa_nets=off|blockSecName=test name|blockTechName=brian t
+est|blockAdminName=test admin|blockSecName=John G. Smooth|blockTechPh
+one=256-555-1212|blockAdminName=Lucy P. Wallice|blockAdminId=8878787|
+block_name=unknown|blockSecId=787878|blockAdminEmail=lucy.p.wallice@n
+asa.gov|blockTechName=TEST LAN|blockSecPhone=256-555-3232|blockTechEm
+ail=terCInternal@mail.nasa.gov|blockSecEmail=John.goody@nasa.gov|nasa
+_nets=Soff
Update:
I've added the Sort::Key::IPv4 module to use its ipv4sort on the IP4 addresses in your data set. The advantage is an ordered list of results. Its limitation is not sorting on IP6 addresses. This IP4 sorting was easily added, and can be easily removed if not needed.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|