首页 > 系统服务 > 详细

[leetcode shell]194. Transpose File

时间:2017-03-06 01:27:53      阅读:254      评论:0      收藏:0      [点我收藏+]

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:

name age
alice 21
ryan 30

 

Output the following:

name alice ryan
age 21 30


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

 

[leetcode shell]194. Transpose File

原文:http://www.cnblogs.com/fcyworld/p/6507470.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!