Hello oysterperl, and welcome to the Monastery!
I assume the repetition of “8” in the desired output is a mistake? If so, the following script should give you an idea of how to proceed:
use strict; use warnings; my $header = <DATA>; chomp $header; $header =~ s/ ^ \s+ //x; my @columns = split /\s+/, $header; my $columns = scalar @columns; my @lines = <DATA>; my $data = pop @lines; chomp $data; my @data = split /\s+/, $data; print "\t", join("\t", @columns), "\n"; for my $line (@lines) { chomp $line; print $line; for my $i (1 .. $columns) { print("\t", shift @data) if @data; } print "\n"; } __DATA__ a b c d e f g h aa bb cc dd aa bb cc dd aa bb cc dd 1 2 3 4 5 6 7 8 9 10 11 12 13 1 +4 15 16
Output:
17:37 >perl 2021_SoPW.pl a b c d e f g h aa 1 2 3 4 5 6 7 8 bb 9 10 11 12 13 14 15 16 cc dd aa bb cc dd aa bb cc dd 17:37 >
I don’t know what you mean by “All the rows need to be filled” though.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Cutting text from the end of the file and adding it to the top
by Athanasius
in thread Cutting text from the end of the file and adding it to the top
by oysterperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |