I want to grep data from multiple files then combine the data I grep into a single log. My input files as such:
Cell_a freq_100 50
Cell_a freq_200 6.8
Cell_b freq_100 70
Cell_a freq_100 100
Cell_a freq_200 10.5
Cell_b freq_100 60
<cell> <freq> <value_frm__file2> <value_frm_file1> <etc>
Cell_a freq_100 100 50
Cell_a freq_200 10.5 6.8
Cell_b freq_100 60 70
I only able to grep the value once in a time. Can someone help in solving this? Thanks a bunch!
Try this:
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(switch say);
my %record;
while (<>) {
chomp;
my ($cell, $freq, $num) = split " ";
push @{$record{$cell}->{$freq}}, $num;
}
while (my ($cell, $freqs) = each %record) {
while (my ($freq, $nums) = each %$freqs) {
say "$cell $freq ", join(" ", @$nums);
}
}
Run it like this:
./t.pl input1.txt input2.txt