You're tasked with transposing a text file - essentially rotating it 90 degrees so that rows become columns and columns become rows. This is a classic shell scripting challenge that tests your ability to manipulate structured text data.
The Challenge: Given a text file file.txt where each row contains the same number of space-separated fields, transform it so that:
- The 1st column of all rows becomes the 1st row
- The 2nd column of all rows becomes the 2nd row
- And so on...
Example: If your file contains:name age city
john 25 paris
jane 30 london
The transposed output should be:name john jane
age 25 30
city paris london
This operation is fundamental in data processing, similar to transposing a matrix in mathematics or pivoting data in spreadsheets.
Input & Output
Visualization
Time & Space Complexity
Where n is number of rows and m is number of columns - we read each cell twice
Need to store the entire file content in memory as arrays
Constraints
- Each row has the same number of columns
- Fields are separated by single space character ' '
- File is not empty and contains at least one row
- Maximum file size should be reasonable for shell processing
- Shell environment: bash, awk, or similar Unix tools available