描述
Given a text file file.txt
, transpose its content.
You may assume that each row has the same number of columns and each field is separated by the ‘ ‘ character.
For example, if file.txt
has the following content:
1 | name age |
Output the following:
1 | name alice ryan |
解决方案
依旧是强大的 Awk。NR 是 Awk 的内建变量,表明目前读到的行号,NF 也是 Awk 的内建变量,记录当前行的字段数量。
1 | # Read from the file file.txt and print its transposed content to stdout. |