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的更多相关文章

  1. LeetCode(194.Transpose File)(awk进阶)

    194. Transpose File Given a text file file.txt, transpose its content. You may assume that each row ...

  2. LeetCode Shell Problems

    195. Tenth Line -- 第十行 How would you print just the 10th line of a file? Solution: awk 'NR==10' file ...

  3. 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]

    首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...

  4. run commands in linux shell using batch file

    adb shell as root after device rooted once device rooted, we must perform "su" before we g ...

  5. [LeetCode] Transpose File 转置文件

    Given a text file file.txt, transpose its content. You may assume that each row has the same number ...

  6. [Bash]LeetCode194. 转置文件 | Transpose File

    Given a text file file.txt, transpose its content. You may assume that each row has the same number ...

  7. Shell重定向&>file、2>&1、1>&2的区别

    shell上: 0表示标准输入 1表示标准输出 2表示标准错误输出 > 默认为标准输出重定向,与 1> 相同 2>&1 意思是把 标准错误输出 重定向到 标准输出. & ...

  8. Transpose File

    Given a text file file.txt, transpose its content. You may assume that each row has the same number ...

  9. VB.net shell、IO.File.Open、Process.Start、Shellexecute API 运用经验总结

    打开文件还有很多方法,但我了解到运用较多的是上面几种- -,为了防止以后忘记,先把了解到的写下来. 1.Shell 这个看了很多网页,最靠谱的运用方法: Shell("cmd.exe /c ...

随机推荐

  1. 基本控件文档-UIKit结构图

    CHENYILONG Blog 基本控件文档-UIKit结构图 Fullscreen   UIKit结构图 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博htt ...

  2. 标准vim配置文件 带注释(适合C++编译)

    我的vim配置文件,适合大多数人习惯 """""""""""""&qu ...

  3. 【leetcode 简单】 第一百四十六题 最长和谐子序列

    和谐数组是指一个数组里元素的最大值和最小值之间的差别正好是1. 现在,给定一个整数数组,你需要在所有可能的子序列中找到最长的和谐子序列的长度. 示例 1: 输入: [1,3,2,2,5,2,3,7] ...

  4. linux可运行的shell脚本与设置开机服务启动(自己总结)

    完整的ln命令参考:http://www.runoob.com/linux/linux-comm-ln.html ln :创建连接文件 - 默认创建的是硬连接,好比复制 ,但是两个文件会同步 命令:l ...

  5. 再战CS231-快速排序

    1.用python实现快速排序 print quicksort([3,6,8,10,1,2,1]) # Prints "[1, 1, 2, 3, 6, 8, 10]" ''' @a ...

  6. 浅析Postgres中的并发控制(Concurrency Control)与事务特性(上)

    转载:https://www.cnblogs.com/flying-tiger/p/9567213.html#4121483#undefined PostgreSQL为开发者提供了一组丰富的工具来管理 ...

  7. 你需要知道的12个Git高级命令【转】

    转自:http://www.linuxidc.com/Linux/2016-01/128024.htm 众所周知,Git目前已经是分布式版本控制领域的翘楚,围绕着Git形成了完整的生态圈.学习Git, ...

  8. linux服务器登录时慢出现卡顿

    使用SSH远程登录Linux在输入用户名之后在过了好几秒之后才会出现输入密码.严重影响工作效率.登录很慢,登录上去后速度正常,这种情况的主要原因为: DNS反向解析的问题 SSH在登录的时候一般我们输 ...

  9. J2V8 For Android

    J2V8是基于Google的JavaScript引擎V8的Java开源项目,实现Java和JavaScript的相互调用.并对Android平台提供支持,最新版本提供了aar格式的类库包方便Andro ...

  10. jupyter(ipython notebook) 安装和入门教程

    近期大家无论是自己做数据分析还是紧急答辩做PPT,可能都需要画一些数据的展示图:以前大家都是用excel画图,但excel画图存在一定的局限性,比如你要画个累积直方图,excel就很麻烦了,所以给大家 ...