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)
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityperl
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