in reply to Cutting text from the end of the file and adding it to the top
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Cutting text from the end of the file and adding it to the top
by oysterperl (Novice) on Sep 30, 2019 at 09:40 UTC | |
by hippo (Archbishop) on Sep 30, 2019 at 10:15 UTC | |
by oysterperl (Novice) on Sep 30, 2019 at 10:34 UTC | |
by poj (Abbot) on Sep 30, 2019 at 11:54 UTC | |
by Utilitarian (Vicar) on Sep 30, 2019 at 12:21 UTC | |
by oysterperl (Novice) on Oct 01, 2019 at 05:26 UTC | |
|