So I see the plot thickens... I made a straightforward modification to previous code to account for the fact that you have pairs of things instead of single space separated things in the input data. I am confused by your last example output line 10GBE_ADDR1 (ANALOG:107) U212.19. I just assumed that this was a cut-n-paste error? If not, then you have a lot more explaining to do about "what the rules are".
I am not sure if this is what you need, but we are incrementally closer...
#!/usr/bin/perl
use warnings;
use strict;
while (my $line = <DATA>)
{
next if $line =~ /^\s*$/; #skip blank lines
my ($label, @rest) = split ' ', $line;
my @pairs;
while (@rest)
{
my $first_num_thing = shift @rest;
my $paren_thing = shift @rest;
push @pairs, "$first_num_thing $paren_thing";
}
@pairs = sort @pairs; #may need special sort??
foreach my $col (@pairs)
{
print "$label $col\n";
}
}
=prints
10GBE_ADDR1 R3629.2 (ANALOG:107)
10GBE_ADDR1 R3633.1 (ANALOG:107)
10GBE_ADDR1 U212.19 (INPUT:107)
=cut
__DATA__
10GBE_ADDR1 R3629.2 (ANALOG:107) R3633.1 (ANALOG:107) U212.19 (INPUT:1
+07)
Now of course in your "real" code vs my "demo" code, use something more descriptive that "$paren_thing". I am sure in your actual context that thing has some name or description that makes a lot more sense than that!
I hope that you have read my previous answer to your questions and that this post makes more sense to you now. As with the previous code post, this is "runnable code" as is.
What I expect you to do is use my code as a starting point. Play with it. Modify it. I am trying to provide enough info to get you "unstuck". You need to start writing some code yourself. There are of course other ways to write this code. I attempted to be straightforward and not overly fancy.
Update:
Ok, I will demo another technique. If you can understand how both of these programs work, then you are well on your way. Split and "match global" can solve an enormous percentage of file parsing problems.
#!/usr/bin/perl
use warnings;
use strict;
while (my $line = <DATA>)
{
next if $line =~ /^\s*$/; #skip blank lines
my ($label, $rest) = split ' ', $line,2;
(my @pairs) = $rest =~ /(\S+\s+\S+)/g; #called "match global";
@pairs = sort @pairs;
foreach my $col (@pairs)
{
print "$label $col\n";
}
}
=prints
10GBE_ADDR1 R3629.2 (ANALOG:107)
10GBE_ADDR1 R3633.1 (ANALOG:107)
10GBE_ADDR1 U212.19 (INPUT:107)
=cut
__DATA__
10GBE_ADDR1 R3629.2 (ANALOG:107) R3633.1 (ANALOG:107) U212.19 (INPUT:1
+07)
|