Print the second column after the first column and so on.

Joined
Dec 28, 2021
Messages
1
Reaction score
0
I am trying to edit a file that contains:
Time Column 1 Column 2 Column 3.
I need to print column 2 after column 1like this:

Time Column1
Column 2
Column 3
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Just work through the file line by line, split each line, and print them out however you want.

Perl:
#!/usr/bin/env perl

use warnings FATAL => 'all';
use strict;

sub main {
        my @args = @_;
        my $file = shift(@args);
        open(my $fh, '<', $file) || die($!);
        while (my $line = <$fh>){
                chomp($line);
                my @c = split(/ /, $line);
                print("$c[0] $c[1]\n$c[2]\n$c[3]\n");
        }
        close($fh);
        return;
}

unless (caller){
        exit(main(@ARGV) || 0);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top