Hi monks
In a file I have a text in the format
[server1] /tmp/location1/file.log /tmp/location2/file.log [server2] /usr/loc1/file.log /usr/loc2/file.log [server3] /citrix/dir3/file.log
What I would like to do is read each server from the file and associate the logs to that server. For example
server1:/tmp/location1/file.log,tmp/location2/file.log server2:/usr/loc1/file.log,/usr/loc2/file.log server3:/citrix/dir3/file.log
I just need to know the best way to map the server to the logs, probably via hash
Code so far
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @lines; my @data; open (my $file, '<', 'log') or die $!; while (my $line = <$file>) { if ($line =~ /\[(.*)\]/) { push (@lines, $1); next; } if ($line =~ /(\/.*)/) { push (@data, $1); next; } } my $val = join(",",@data); close $file; foreach(@lines){ print "$_:$val\n";
Thanks in advance
In reply to File Manipulation by Mark.Allan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |