LeetCode刷题实战194:转置文件
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.
题意
示例
示例:
假设 file.txt 文件内容如下:
name age
alice 21
ryan 30
应当输出:
name alice ryan
age 21 30
解题
思路:先用awk获取列数,再循环
k=`awk '{print NF}' file.txt | head -1`
for ((i=1;i<=k;i++))
do
awk '{print $'$i'}' file.txt | xargs
done
赞 (0)