Using Raku (formerly known as Perl_6)
raku -e 'say .key, " => ", .value.words[1,3,5...*] for lines.split(/<[:\s]>/, :skip-empty).rotor(2).classify( *.[0]);'
Sample Input:
ABCDEFG_10_node10:2154 ABCDEFG_10_node10:54
ABCDEFG_10_node10:2254 ABCDEFG_10_node10:64
ABCDEFG_10_node10:410 ABCDEFG_10_node10:10
ABCDEFG_10_node10:210 ABCDEFG_10_node10:10
ABCDEFG_10_node10:365
ABCDEFG_10_node10:890
ABCDEFG_10_node10:741
XXYZZ_71_node2:24: XXYZZ_71_node2:504:
X3y5z_53_node1:664: X3y5z_53_node1:990:
RCTY_11_node2:224: RCTY_11_node2:234:
Sample Output:
XXYZZ_71_node2 => (24 504)
RCTY_11_node2 => (224 234)
ABCDEFG_10_node10 => (2154 54 2254 64 410 10 210 10 365 890 741)
X3y5z_53_node1 => (664 990)
Briefly, lines
are read in, destructively split
on :
and \s
(omitting any empty elements via :skip-empty
), rotor
(join) every 2 elements, and classify
-ing by the first of each pair. [I could make the call .classify( *.[0].unique)
to clarify the intent, but Raku does the right thing either way].
If the OP really wants the format specified in his/her post, then substitute =>
with :
and add a call to join
at the end of the .value
call, so the whole section prior to for
reads: say .key, ": ", .value.words[1,3,5...*].join(",")
Sample Output (2):
X3y5z_53_node1: 664,990
RCTY_11_node2: 224,234
ABCDEFG_10_node10: 2154,54,2254,64,410,10,210,10,365,890,741
XXYZZ_71_node2: 24,504
https://docs.raku.org/routine/classify
https://raku.org
XXYZZ_71_node2:24:
,X3y5z_53_node1:990:
? or it's just a typo?:
and also extra whitespace. Do we need to deal with that as well?