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
Post a Comment