
2teez
Novice
Sep 28, 2013, 11:04 AM
Post #3 of 9
(16888 views)
|
Re: [liton79] Pattern search in txt file and output them with comma seperated value
[In reply to]
|
Can't Post
|
|
Hi, liton79, You can do like so
use warnings; use strict; my %data; @data{qw(Application Region Server)} = undef; my $key; while (<DATA>) { chomp; next if /^$/; if ( exists $data{$_} ) { $key = $_; } else { push @{ $data{$key} }, $_ if defined $key; } } while ( my ( $key, $value ) = each %data ) { print $key, ' ', join( ", " => @$value ), $/; } __DATA__ Details Application ABC Region NA Server Atom.prod Application NA Region XYZ Server Atom.prod2 You get this:
Server Atom.prod, Atom.prod2 Application ABC, NA Region NA, XYZ
|