Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: split then join based on common value in field

by spazm (Monk)
on Jun 02, 2012 at 00:15 UTC ( #973892=note: print w/ replies, xml ) Need Help??

in reply to split then join based on common value in field

#!/usr/bin/perl use warnings; use strict; use 5.10.0; my $current_ip = ''; my @current = (); while (<DATA>) { chomp; my ( $id, $ip, $key, $value ) = split(/\t/); if ( $ip ne $current_ip ) { say join( '|', $current_ip, @current ) if @current; $current_ip = $ip; @current = (); } push @current, "$key=$value"; } say join( '|', $current_ip, @current ) if @current; #note: data should be tab sep __DATA__ 9885 Room 1105A 9885 Jack 1105A--05D 9885 org_code B703 9885 Building 1268A 114948 nasa_nets off 114948 blockSecName test name 114948 blockTechName brian test 114948 blockAdminName test admin 114949 blockSecName John G. Smooth 114949 blockTechPhone 256-555-1212 114949 blockAdminName Lucy P. Wallice 114949 blockAdminId 8878787 114949 block_name unknown 114949 blockSecId 787878 114949 blockAdminEmail 114949 blockTechName TEST LAN 114949 blockSecPhone 256-555-3232 114949 blockTechEmail 114949 blockSecEmail 114949 nasa_nets off
outputs:|Room=1105A|Jack=1105A--05D|org_code=B703|Building=1268A|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|blockTechName=TEST LAN|blockSecPhone=256-555-3232|blockTechEm||nasa +_nets=off

Comment on Re: split then join based on common value in field
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973892]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-11-26 00:18 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls