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
Note:
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行
 
#从第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的更多相关文章

  1. Leetcode 195 Tenth Line

    Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...

  2. [LeetCode] 195. Tenth Line 第十行

    Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...

  3. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  4. Tenth Line

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  5. [Bash]LeetCode195. 第十行 | Tenth Line

    Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...

  6. [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 ...

  7. LeetCode OJ:Tenth Line(文件第十行)

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  8. 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]

    首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...

  9. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

随机推荐

  1. 51nod 1206 && hdu 1828 Picture (扫描线+离散化+线段树 矩阵周长并)

    1206 Picture  题目来源: IOI 1998 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  关注 给出平面上的N个矩形(矩形的边平行于X轴 ...

  2. 【Revit API】创建工作集并将element加入工作集中

    话不多说,直接上代码! public class WorkSetHelper { public void AddElementsToWorkSet(Document doc, List<Elem ...

  3. webpack全局引入库

    我们在日常开发的时候会遇到一些每个页面都可能会引用到的库(例如jquery) 这可能会导致我们在每一个页面都需要写这样一个语句: import $ from 'jquery'; 可能有人会担心,最后打 ...

  4. JavaScript条件和循环以及异常处理

    JavaScript条件和循环以及异常处理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.布尔类型(Boolean) 布尔类型仅包含真假,与Python不同的是其首字母小写. ...

  5. bzoj千题计划205:bzoj1966: [Ahoi2005]VIRUS 病毒检测

    http://www.lydsy.com/JudgeOnline/problem.php?id=1966 f[i][j] 表示s的前i个和t的前j个是否匹配 转移看代码 注意初始化: f[0][0]= ...

  6. bzoj千题计划184:bzoj1261: [SCOI2006]zh_tree

    http://www.lydsy.com/JudgeOnline/problem.php?id=1261 dp[l][r][dep]  区间[l,r]内的节点,根在dep层的最小代价 枚举根i,dp[ ...

  7. day63_SpringMVC学习笔记_01

    1.JAVAEE体系结构 JAVAEE体系结构图如下所示: 2.什么是springmvc? 什么是mvc? Model1 Model2 SpringMVC是什么? SpringMVC是一个web层mv ...

  8. plsql免安装客户端的配置

    不安装oracle,在安装了plsql之后,需要连接数据库,连接数据库需要在tns中tnsnames.ora中配置 首先需要两个文件: network instantclient-basic-win3 ...

  9. Javascript - Vue - 指令

    指令 v-cloak 解决闪烁,闪烁是指在网速较慢的情况下可能会出现插值表达式{{}}还没有填充数据时会把该表达式直接显示在页面上,如果不希望看到插值表达式则可以使用v-cloak指令,具体做法如下 ...

  10. Xgboost理解

    一.xgboost模型函数形式 xgboost也是GBDT的一种,只不过GBDT在函数空间进行搜索最优F的时候,采用的是梯度下降法也就是一阶泰勒展开:而xgboost采用的是二阶泰勒展开也就是牛顿法, ...