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. 【leetcode 简单】 第九十一题 找不同

    给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "abcd&quo ...

  2. 【前端】直击源头的让你3秒理解并且会用Jsonp!!!

    1. 同源策略 ajax之所以需要“跨域”,罪魁祸首就是浏览器的同源策略.即,一个页面的ajax只能获取这个页面相同源或者相同域的数据. 如何叫“同源”或者“同域”呢?——协议.域名.端口号都必须相同 ...

  3. v4l2API无法执行VIDIOC_DQBUF的问题

    一.PC虚拟机下ubuntu14.04.1环境下 源文件:show.c  USB摄像头格式yuyv: 申请缓冲帧数2,分辨率640*480  阻塞无法执行 申请缓冲帧数4,分辨率640*480  阻塞 ...

  4. 2016.5.21——atoi()函数的测试

    对函数atoi()函数的测试: atoi()函数将字符串型转换为整型 代码: #include "stdafx.h" #include "iostream" # ...

  5. ubuntu 18.04 安装 flash

    下载源码包, 解压 sudo cp Downloads/flash_player_npapi_linux.x86_64/libflashplayer.so /usr/lib/mozilla/plugi ...

  6. Linux嵌入式交叉编译环境 的搭建【转】

    转自:http://blog.csdn.net/woaixiaozhe/article/details/7395435 1. 安装标准的C开发环境,由于Linux安装默认是不安装的,所以需要先安装一下 ...

  7. LinuxUSB驱动程序调试--009:编写应用程序---验证协议【转】

    转自:http://biancheng.dnbcw.info/linux/257411.html [1] 如何编译X86下的 uBuntu APP---非常简单:            gcc -o ...

  8. WCF 数据契约(DataContract)

    服务契约定义了远程访问对象和可供调用的方法,数据契约则是服务端和客户端之间要传送的自定义数据类型. 一旦声明一个类型为DataContract,那么该类型就可以被序列化在服务端和客户端之间传送,如下所 ...

  9. linux 安装 Elasticsearch6.4.0详细步骤以及问题解决方案

    1.jdk 安装 参考资料:https://www.cnblogs.com/shihaiming/p/5809553.html 2.elasticsearch 安装 下载:https://artifa ...

  10. JavaScript 中的回调函数

    原文:http://javascriptissexy.com/ 翻译:http://blog.csdn.net/luoweifu/article/details/41466537 [建议阅读原文,以下 ...