An efficient way to transpose a file in Bash

awk  -F'  '                                               #FS
' {
    for (i=1; i<=NF; i++)  {
        a[NR,i] = $i
    }
}
NF>p { p = NF }
END {   
    for(j=1; j<=p; j++) {
        str=a[1,j]
        for(i=2; i<=NR; i++){
            str=str" "a[i,j];                           #OFS
        }
        print str
    }

}'  file > NEW_file

Comments

Popular posts from this blog

梅林380固件支持vless,xray,trojan, trojan go

Setup OpenVPN client auto connects to remote server after reboot in AC3100, AC88U Merlin system