195 Tenth Line
Given a text file file.txt
, print just the 10th line of the file.
Example:
Assume that file.txt
has the following content:
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Your script should output the tenth line, which is:
Line 10
1. If the file contains less than 10 lines, what should you output?
2. There's at least three different solutions. Try to explore all possibilities.
#从第10行开始显示,然后取第一行
tail -n + file.txt | head -n
#打印第10行
sed -n 10p file.txt
awk 'NR==10 {print $0}' file.txt
awk 'NR==10 ' file.txt
cnt=
while read line
do
let cnt++
if [ $cnt -eq ];then
echo $line
exit
fi
done < file.txt
195 Tenth Line的更多相关文章
- Leetcode 195 Tenth Line
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [LeetCode] 195. Tenth Line 第十行
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- Tenth Line
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- [Bash]LeetCode195. 第十行 | Tenth Line
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [LeetCode] 195. Tenth Line_Easy tag: Bash
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- LeetCode OJ:Tenth Line(文件第十行)
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]
首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
随机推荐
- error::尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
1.VS出现此问题 问题分析:本地电脑安装的oracle客户端为64位客户端,vs启动网站默认启动自带的32位IIS Express,所以出错. 解决方案: 方案1.本地电脑安装oracle32位客户 ...
- ctags相关
ctags相关 首先肯定是下载安装了.这点不用多讲,根据自己的操作系统或者平台,使用相应的包管理工具或者源码编译安装都可以. 下载完之后,在想要使用ctags帮助查找的文件夹(一般是项目的根目录)下输 ...
- 后Hadoop时代的大数据技术思考:数据即服务
1. Hadoop 的神话正在破灭 IBM leads BigInsights for Hadoop out behind barn. Shots heard IBM has announced th ...
- OI中的莫比乌斯反演
OI中的莫比乌斯反演 莫比乌斯函数 想要学习莫比乌斯反演,首先要学习莫比乌斯函数. 定义 莫比乌斯函数用\(\mu(x)\)表示.如果\(x\)是\(k\)个不同质数的积,则\(\mu(x) = (- ...
- winform里宿主WCF,并传递winform变量给WCF
最近客户要求把服务器端程序里的二个功能用service的方式提供出来,方便调用.首先想着单独建一个wcf 服务的项目,但是因为要用到server端程序winform里的变量,因此只能在winform里 ...
- 解题:SDOI 2017 硬币游戏
题面 板板的生成函数做法太神仙了,我跑了 朴素的做法是建立AC自动机变成图上的随机游走问题 来仔细考虑一下转移,把状态分成非结尾状态和结尾状态.在一个非结尾状态后补一个串是一定能到达目标串的,但是如果 ...
- 关于http请求时 安全协议问题 PKIX path building failed 解决办法
该问题的解决办法 1.在请求前需要将证书导入,不推荐 2.绕开安全协议处理 下面的代码时一段http请求并且绕开安全协议.可直接使用 /** * * @param url 需要请求的网 ...
- codeblocks编译器
发现网络有些编译器没有MinGW,特此留一文件: https://pan.baidu.com/s/1pLltzvH 有时下载codeblocks后编译不了,还要修改MinGW的位置,找到MinGW文件 ...
- Go_22: Golang 命令行 test 应用
1. 测试某一个包下的所有测试用例 cd /myGoProject/src/go-test/utils go test -v "-v" 参数 go test -v ... 表示无论 ...
- django2.0 官方中文文档地址
django2.0 官方开始发布中文文档了,之前还想着一直翻译完成所有有必要的内容,想着可以省事一些了,打开以后看了一下,发现官方的中文文档还没翻译完成, 现在(2018-7-10)最新章节是是 编 ...