Tenth Line
How would you print just the 10th line of a file?
For 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.
awk '
{
if(NR==){
print $
}
}
' < file.txt
过程中忘了重定向文件
awk '
{
a++;
if(a == ){
print $;
}
}
' < file.txt
不使用NR
awk '
{
a++;
if(a == ){
b = $;
}
}
END{
if(a >= ){
print b;
}
}
' < file.txt
Tenth Line的更多相关文章
- [LeetCode] 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 ...
- 195 Tenth Line
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 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] 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 All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
随机推荐
- Unity3d shader之卡通着色Toon Shading
卡通着色的目的是为了让被着色物体显得过渡的不那么好,明暗交界线很明显,等等卡通风格的一系列特征, 也叫Non-photorealisticrendering非真实渲染 重点要做到两点: 1. 描 ...
- 【转】OpenGL基础图形编程(一)
原文:http://blog.chinaunix.net/uid-20638550-id-1909183.html 分类: 一.OpenGL与3D图形世界 1.1.OpenGL使人们进入三维图形世界 ...
- 阻止iOS设备锁屏
[[UIApplicationsharedApplication] setIdleTimerDisabled: YES];
- (转载)关于having 1=1 和group by 爆表的思考和总结
上次在网上看到一篇关于having 1=1 和group by 爆表注射的文章,看得我晕乎乎的,为了了解其根本原理,我稍微学习了下数据库知识,翻了下资料,但有些资料找不到,于是,开始发挥本天才的思维来 ...
- html/php, 二个文本框求和,在第三个框中显示
我想要实现的是第三个文本框本来输出的是默认值,按了提交按钮之后,显示了一个我通过php某个计算后想要输出的值,如何实现?就好比说:我输入两个数,我按了个提交按钮之后,那个第三个文本框本来输出是“输出框 ...
- oracle hints
oracle hints 今天是2013-10-08,对于oracle hint有很多,具体可以参考联机手册: http://docs.oracle.com/cd/E11882_01/server.1 ...
- 【设计模式 - 2】之单例模式(Singleton)
1 模式简介 单例模式在代码中是非常常用的,如线程池.数据库连接.注册表.共享资源.一些非常消耗资源的组件,等等. 单例模式主要解决如下问题: 确保一个特殊类的实例是独一无二的: 确保这个类 ...
- OPENSHIFT MYSQL使用Navicat连接配置
最近一直在研究openshift免费空间的使用,对于如何用本地的数据库工具连接一直在找方法,呵呵,初学者. 以下方法可以实现: 1.在本地命令行中执行命令:rhc port-forward 应用名 如 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(14)-系统小结
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(14)-系统小结 不知不觉已经过了13讲,(本来还要讲多一讲是,数据验证之自定义验证,基于园友还是对权限这 ...
- POJ 1737 统计有n个顶点的连通图有多少个 (带标号)
设f(n)为所求答案 g(n)为n个顶点的非联通图 则f(n) + g(n) = h(n) = 2^(n * (n - 1) / 2) 其中h(n)是n个顶点的联图的个数 这样计算 先考虑1所在的连通 ...