0

Input:

X Y
1 11
1 12
2 21
2 22

Desired Output:

11 12
21 22

I want to transpose the CSV file by the value of column 1. In this example, for X = 1, transpose (11, 12)^T to (11, 12); for X = 2, transpose (21, 22)^T to (21, 22)

0

1 Answer 1

1

perl

perl -lane '
    push @{$rows{$F[0]}}, $F[1] if $. > 1
  } END {
    $, = " ";
    print @{$rows{$_}} for (sort keys %rows);
' file

awk, assumes input is sorted on column 1:

awk '
    NR == 1 {next}
    NR == 2 {key = $1} 
    $1 != key {print ""; key = $1} 
    {printf "%s ", $2} 
    END {print ""}
' file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .