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. laravel更新某一个或几个字段

    //更新会员状态status $ary_where = array(); $ary_where[] = ['id', '=', $int_id]; $result = $this->obj_ad ...

  2. mysql定时删除数据

    删除三天前的数据的sql DELETE FROM table WHERE created_on < DATE_SUB(CURDATE(),INTERVAL 3 DAY); CURDATE() 返 ...

  3. js中call与apply的区别以及使用~

    今天看了一下call与apply的区别~~ <!DOCTYPE html> <html> <head> <title>testCall</titl ...

  4. Centos7网络配置(VMware)

    在VM虚拟机上装了Centos7,想要用xshell5连接操作,配置网络花了整整一个上午的时间,真是心酸. 登陆后,使用命令 ip addr查看了本机的网络 可以看到我的网络配置文件是ens33, 使 ...

  5. Python概念-反射之文化底蕴版:反正射了

    什么是反射 光在两种物质分界面上改变传播方向又返回原来物质中的现象,叫反射! 以上,是反射的物理定义,与python中的反射概念,完全没有任何关系 书归正传:反射 就是通过字符串的形式,操作对象相关的 ...

  6. 关于禁用"请停用以开发者模式运行的扩展程序"提示

    有兴趣研究谷歌浏览器扩展开发,但每次开启高版本chrome都会有烦人的提示 因为我用的360急速,目前还有提示,但使用原生chrome连插件都给删了,无语

  7. 2017 jq 总结

    $(el).parent()         获取父级元素 .parents('th')        获取祖元素th .parentsUntil("th")         找到 ...

  8. 【HASPDOG】卸载

    rpm -qa | grep aksusdb rpm -e aksusdb... rm -rf /var/hasplm

  9. 内核工具 – Sparse 简介【转】

    转自:http://www.cnblogs.com/wang_yb/p/3575039.html Sparse是内核代码静态分析工具, 能够帮助我们找出代码中的隐患. 主要内容: Sparse 介绍 ...

  10. REX系统了解1

    REX是高通开发出来的一个操作系统,起初它是为了在Inter 80186处理器上应用而开发的,到后来才转变成应用在ARM这种微处理器上.他历经了很多版本,代码也越来越多,功能也越来越完善.REX只用不 ...