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 ...
随机推荐
- luogu1312
有趣的题面 超有趣的dfs大模拟,码了巨久,卡时过了此题qaq #include <cstdio> #include <cstring> #include <algori ...
- 学习Spring Boot:(十四)spring-shiro的密码加密
前言 前面配置了怎么使用 shiro ,这次研究下怎么使用spring shiro的密码加密,并且需要在新增.更新用户的时候,实现生成盐,加密后的密码进行入库操作. 正文 配置凭证匹配器 @Bean ...
- 【转】如何快速识别应用MOS管,几张图片就搞定了
三极管是流控型器件,MOS管是压控型器件,两者存在相似之处.三极管机可能经常用,但MOS管你用的可能较少.对于MOS管先抛出几个问题: 如何区分P-MOS和N-MOS: 如何区分MOS的G.D.S管脚 ...
- [APIO2018] Duathlon 铁人两项
不经过重点,考虑点双 点双,考虑圆方树 两个点s,t,中间路径上,所有点双里的点都可以经过,特别地,s,t作为割点的时候,不能往后走,也就是不能经过身后的方点 也就是,(s,t)经过树上路径上的所有圆 ...
- k8s role
转 https://blog.qikqiak.com/post/add-authorization-for-kubernetes-dashboard/ 另外还可以参考这个 https://mrit ...
- MySQL存储引擎对比
MySQL存储引擎对比 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL的存储引擎 大家应该知道MySQL的存储引擎应该是表级别的概念,因为我们无法再创建databas ...
- 【转载】视频CDN技术原理与流程说明
视频CDN专为移动互联网视频内容分发量身定做的一套自主研发的分布式平台,该平台以深圳为中心,分布在全国各地BGP机房的服务器为边缘节点,汇聚中国电信.中国联通.中国移动.中国教育网等运营商网络资源,构 ...
- Phalcon框架之———— 2.0升级到3.0 问题Model验证问题解决
Github源码:https://github.com/phalcon/cphalcon/tree/master/phalcon/validation/validator Phalcon 2.0 Mo ...
- pgadmin导出excel
生成导入sql 第一行公式:="insert into province(code,name) values("&A2&",'"&B2& ...
- 公告:关注canvas的同学注意了
因为我之前把基础大致都帮各位详细讲过了! 什么fill,line,乱七八糟的一堆.都有demo了 所以我最近写起来可能会快很多了!如果有不明白的只能请各位回顾下之前的文章了 毕竟如果按照这个进度写文章 ...