Skip to content

194. Transpose File 👎

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
awk '{
  for (i = 1; i <= NF; ++i) {
    if (NR == 1) {
      arr[i] = $i;
    } else {
      arr[i] = arr[i] " " $i;
    }
  }
} END {
  for (i = 1; i <= NF; ++i) {
    print arr[i];
  }
}' file.txt