[leetcode shell]194. Transpose File
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的更多相关文章
- LeetCode(194.Transpose File)(awk进阶)
194. Transpose File Given a text file file.txt, transpose its content. You may assume that each row ...
- LeetCode Shell Problems
195. Tenth Line -- 第十行 How would you print just the 10th line of a file? Solution: awk 'NR==10' file ...
- 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]
首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...
- 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 ...
- [LeetCode] Transpose File 转置文件
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- [Bash]LeetCode194. 转置文件 | Transpose File
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- Shell重定向&>file、2>&1、1>&2的区别
shell上: 0表示标准输入 1表示标准输出 2表示标准错误输出 > 默认为标准输出重定向,与 1> 相同 2>&1 意思是把 标准错误输出 重定向到 标准输出. & ...
- Transpose File
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- VB.net shell、IO.File.Open、Process.Start、Shellexecute API 运用经验总结
打开文件还有很多方法,但我了解到运用较多的是上面几种- -,为了防止以后忘记,先把了解到的写下来. 1.Shell 这个看了很多网页,最靠谱的运用方法: Shell("cmd.exe /c ...
随机推荐
- 简单的多对一传输ns2仿真
实验名称:简单的多对一传输仿真 实验目的:1.研究怎么实现多对一传输. 实验步骤: 1.写c++代码并注册报文头. 先说一下多对一传输的方式.最开始,接收端发送控制报文给所有的发送端,告诉他们要发送多 ...
- 【BZOJ】2655: calc 动态规划+拉格朗日插值
[题意]一个序列$a_1,...,a_n$合法当且仅当它们都是[1,A]中的数字且互不相同,一个序列的价值定义为数字的乘积,求所有序列的价值和.n<=500,A<=10^9,n+1< ...
- #error#优化#Model#理解下面这句话错误所导致的错误:"传入一个对象,那么你就拥有了对象的属性"2
CHENYILONG Blog #error#优化#Model#理解下面这句话错误所导致的错误:"传入一个对象,那么你就拥有了对象的属性"2 © chenyilong. Power ...
- mvn打war包以及解压包的方法
有时候我们需要查看打成war包之后的目录,如果是maven项目我们可以直接用maven打包. 1.maven打包: 第一种: mvn package 如果不行先 mvn clean一下 第二种:(掌握 ...
- PATH变量重复
命令: export PATH=$(echo $PATH | tr : "\n"| sort | uniq | tr "\n" :) Code: awk -F: ...
- device tree --- #address-cells and #size-cells property【转】
转自:http://www.cnblogs.com/youchihwang/p/7050846.html device tree source Example1 / { #address-cells ...
- 【Linux技术】autotools制作makefile过程详解【转】
转自:http://www.cnblogs.com/lcw/p/3159461.htmlPreface Makefile固然可以帮助make完成它的使命,但要承认的是,编写Makefile确实不是一件 ...
- 去除TFS版本控制
对于曾经做过TFS版本控制的项目,在版本控制服务不可用的时候,依然会在每次打开项目的时候都提示:当前项目是版本控制的项目,但是当前版本控制不可用,balabala的信息,如果是需要进行版本控制的项目在 ...
- JS实现全选、反选、不选
JS实现全选.反选.不选 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- supervisor管理uwsgi
1. 前言 传统的管理uwsgi服务: 1. 通过shell脚本来编写start restart stop函数来控制 2. 比较麻烦,有时候控制写的烂,还会出现意想不到的错误 supervisor进行 ...