坐山雕

导航

bash transpose csv

transpose()
{
awk '
BEGIN {
FS = ",";
OFS = ",";
}

{
if (max_nf<NF)
max_nf=NF
max_nr=NR
for (x=1; x<=NF; ++x)
vector[x, NR]=$x
}

END {
for (x=1; x<=max_nf; ++x) {
for (y=1; y<=max_nr; ++y)
printf("%s,", vector[x, y])
printf("\n")
}
}' ${1}
}

transpose ${1}

https://stackanswers.net/questions/how-to-do-a-transpose-in-bash-awk-other-duplicate

posted on 2021-08-10 18:45  坐山雕  阅读(31)  评论(0编辑  收藏  举报