Rajeev Prasad wrote:

Hello,

Hello,

I tried following code but it is not working.

I have a file with many lines(records) where field separator is space.

I want to convert rows to columns, something like...

source:
a b c d
1 2 3 4

output:
a 1
b 2
c 3
d 4


$ echo "a b c d
1 2 3 4" | perl -e'

my @out;
while ( <> ) {
    my @fields = split;
    push @{ $out[ $_ ] }, $fields[ $_ ] for 0 .. $#fields;
    }

for ( @out ) {
    print "@$_\n";
    }
'
a 1
b 2
c 3
d 4



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to