Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 519 Bytes

File metadata and controls

38 lines (28 loc) · 519 Bytes

Transpose File

Description

link


Solution

See Code

s[i] = s[i] " " $i means append($i) on s[i] with " "


Code

O(n)

# Read from the file file.txt and print its transposed content to stdout.
awk '
{
    for (i = 1; i <= NF; i++) {
        if(NR == 1) {
            s[i] = $i;
        } else {
            s[i] = s[i] " " $i;
        }
    }
}
END {
    for (i = 1; s[i] != ""; i++) {
        print s[i];
    }
}' file.txt