我有一个这样的空格分隔文件:
GID_1 AID_1 2
GID_1 AID_2 1
GID_1 AID_3 3
GID_2 AID_1 3
GID_2 AID_2 1
GID_2 AID_3 2
GID_3 AID_1 1
GID_3 AID_2 1
GID_3 AID_3 3
我希望将第1列和第3列转换为第2列,并使用:
(X) GID_1 GID_2 GID_3
AID_1 2 3 1
AID_2 1 1 1
AID_3 3 2 3
我已经放了一个"(X)"因为这个转置会使该字段为空白,这对我来说很好。
拜托,有人可以帮我吗?
答案 0 :(得分:1)
awk
解决方案
awk -F" |_" '
{
g=g>$2?g:$2
a=a>$4?a:$4
arr[$2 " " $4]=$5
}
END {
for (j=1;j<=g;j++)
{
printf "\tGID_%s",j
}
print ""
for (i=1;i<=a;i++)
{
printf "AID_%s",i
for (j=1;j<=g;j++)
{
printf "\t%s",arr[j " " i]
}
print ""
}
}
' file
GID_1 GID_2 GID_3
AID_1 2 3 1
AID_2 1 1 1
AID_3 3 2 3