题目:
给定一个文件 file.txt,转置它的内容。
你可以假设每行列数相同,并且每个字段由 ’ ’ 分隔.
示例:
假设 file.txt 文件内容如下:
name age
alice 21
ryan 30
应当输出:
name alice ryan
age 21 30
解答:
# Read from the file file.txt and print its transposed content to stdout.
awk '{ for (i=1;i<=NF;i++){ if (NR==1){ res[i]=$i } else{ res[i]=res[i] " " $i } } } END{ for (j=1;j<=NF;j++){ print res[j] } }' file.txt
博客围绕文件内容转置问题展开,给定文件 file.txt,要求转置其内容,假设每行列数相同且字段由空格分隔,还给出了示例,最后呈现了解答内容。
815

被折叠的 条评论
为什么被折叠?



