2 files-array->1files

K

kristoff

Hi,
I'm new in perl.
I'm facing to a problem which will appear for most of you not really
tricky, but I'm not comfortable with array stuff, so prefer asking
question is case of someone made this in the past.

I have 2 set of files, text files.
1st one with this format ( systemname;message )


bingo;ERROR Can't be reach port is closed
pppp;system OK
typo;System OK
Ray;ERROR Can't be reach port is closed
blush;ERROR Can't be reach port is closed
bingo;system OK


2nd FILE ( domain;system name ):
HP;ppp
HP;bingo
IBM;typo
COMPAQ;blush
DELL;ray


EXPECTED RESULT :
I would like to match data, to a final txt files ( preferably an html
output ) sorted or not :
HP
ppp System OK
bingo System OK
IBM
typo System OK
COMPAQ
blush ERROR Can't be reach port is closed
DELL
ray ERROR Can't be reach port is closed


Does someone have an idea or already realised this kind of stuff


Many thanks in advance for you help
 
G

Gunnar Hjalmarsson

kristoff said:
I have 2 set of files, text files.
1st one with this format ( systemname;message )

bingo;ERROR Can't be reach port is closed
pppp;system OK
typo;System OK
Ray;ERROR Can't be reach port is closed
blush;ERROR Can't be reach port is closed
bingo;system OK

2nd FILE ( domain;system name ):
HP;ppp
HP;bingo
IBM;typo
COMPAQ;blush
DELL;ray

EXPECTED RESULT :
I would like to match data, to a final txt files ( preferably an html
output ) sorted or not :
HP
ppp System OK
bingo System OK
IBM
typo System OK
COMPAQ
blush ERROR Can't be reach port is closed
DELL
ray ERROR Can't be reach port is closed

What have you tried? Which part of the problem do you have difficulties
with? Where is the code you have written so far?

Please study the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
J

Josef Moellers

kristoff said:
Hi,
I'm new in perl.
I'm facing to a problem which will appear for most of you not really
tricky, but I'm not comfortable with array stuff, so prefer asking
question is case of someone made this in the past.

I have 2 set of files, text files.
1st one with this format ( systemname;message )


bingo;ERROR Can't be reach port is closed
pppp;system OK
typo;System OK
Ray;ERROR Can't be reach port is closed
blush;ERROR Can't be reach port is closed
bingo;system OK


2nd FILE ( domain;system name ):
HP;ppp
HP;bingo
IBM;typo
COMPAQ;blush
DELL;ray


EXPECTED RESULT :
I would like to match data, to a final txt files ( preferably an html
output ) sorted or not :
HP
ppp System OK
bingo System OK
IBM
typo System OK
COMPAQ
blush ERROR Can't be reach port is closed
DELL
ray ERROR Can't be reach port is closed


Does someone have an idea or already realised this kind of stuff

Take a look at hashes and hashes of hashes.
 
J

Joe Smith

kristoff said:
1st one with this format ( systemname;message )
bingo;ERROR Can't be reach port is closed
pppp;system OK
typo;System OK
Ray;ERROR Can't be reach port is closed
blush;ERROR Can't be reach port is closed
bingo;system OK

2nd FILE ( domain;system name ):
HP;ppp
HP;bingo
IBM;typo
COMPAQ;blush
DELL;ray

I would put all the info from the first file into one
hash (key=systemname, val=message), assuming only one
message per systemname.

/(\w+);(.*)/ and $message{$1} = $2;

Put the info from the second file into a second hash
(key=domain, val=ref to anon array containing system names).

/(\w+);(\w+)/ and push @{$systems{$1}},$2;

Then process each key in %systems.

foreach my $domain (sort keys %systems) {
print "something with $domain ...\n";
foreach my $system ( @{$systems{$domain}} ) {
print "something with $system and $message{$system}\n";
}
}

Those should be enough hints to get you going.
-Joe
 
W

William James

kristoff said:
I have 2 set of files, text files.
1st one with this format ( systemname;message )


bingo;ERROR Can't be reach port is closed
pppp;system OK
typo;System OK
Ray;ERROR Can't be reach port is closed
blush;ERROR Can't be reach port is closed
bingo;system OK


2nd FILE ( domain;system name ):
HP;ppp
HP;bingo
IBM;typo
COMPAQ;blush
DELL;ray


EXPECTED RESULT :
I would like to match data, to a final txt files ( preferably an html
output ) sorted or not :
HP
ppp System OK
bingo System OK
IBM
typo System OK
COMPAQ
blush ERROR Can't be reach port is closed
DELL
ray ERROR Can't be reach port is closed

A simple solution in Awk:

BEGIN { FS = ";" }
ARGV[1]==FILENAME { a[$1] = $2; next }
{ if (d != $1)
{ d = $1
print " " d
}
print $2, a[$2]
}

Run with
awk -f 2to1.awk file1 file2

file1:
bingo;ERROR Can't be reach port is closed
ppp;system OK
typo;System OK
ray;ERROR Can't be reach port is closed
blush;ERROR Can't be reach port is closed
bingo;system OK

file2:
HP;ppp
HP;bingo
IBM;typo
COMPAQ;blush
DELL;ray

output:
HP
ppp system OK
bingo system OK
IBM
typo System OK
COMPAQ
blush ERROR Can't be reach port is closed
DELL
ray ERROR Can't be reach port is closed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top