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 ...
随机推荐
- 判断iis是否已经安装
判断iis是否已经安装? 访问http://127.0.0.1 能得到正确页面的是已经安装. 活者查看控制面板-添加删除程序-windows组件-internet信息服务(IIS)前面的没有打勾则没有 ...
- YUV像素和ycbcr
一幅彩色图像的基本要素是什么? 说白了,一幅图像包括的基本东西就是二进制数据,其容量大小实质即为二进制数据的多少.一幅1920x1080像素的YUV422的图像,大小是1920X1080X2=4147 ...
- 查看线程linux cpu使用率
Linux下如何查看高CPU占用率线程 LINUX CPU利用率计算 转 http://www.cnblogs.com/lidabo/p/4738113.html目录(?)[-] proc文件系统 p ...
- 常用Dos命令笔记
0x00 磁盘FAT32格式转NTFS convert e: /fs:ntfs Tips: 语法规则: Converts a FAT volume to NTFS. CONVERT volume /F ...
- Color Cube – 国产的优秀配色取色工具
官方下载地址:http://fancynode.dbankcloud.com/ColorCube2.0.1ForWin.rar 比如今天所要介绍的 Color Cube (配色神器) 就属于“功大于过 ...
- Newtonsoft.Json 与 DataTable的相互转换
1.这里下载:http://www.newtonsoft.com/products/json/ 安装: 解压下载文件,得到Newtonsoft.Json.dll 在项目中添加引用 2.引入 ...
- BZOJ 1878 SDOI 2009 HH项链 树状数组 + 脱机处理
标题效果:一些珠子项链.珠具有不同的颜色.我们问了很多次有多少种不同的颜色有过一段范围. 思考:这个问题让我学会聪明的离线实践.按左端点排序问题.加工出来的位置每种颜色首次出现.每一种颜色的下一次出现 ...
- perf---LINUX内核研究
http://blog.chinaunix.net/uid-10540984-id-3854969.html http://blog.csdn.net/bluebeach/article/detail ...
- 使用navicat 11 出现不能返回存储过程结果的问题
问题: 使用navicat 11 调试存储过程,select返回结果,总是不能返回. 原因: 经google发现,navicat仅支持返回10个resultset,超过则不现实. 解决方法: 减少存储 ...
- 转载:JAVA 正则表达式 (超详细)
在Sun的JavaJDK 1.40版本中,Java自带了支持正则表达式的包,本文就抛砖引玉地介绍了如何使用Java.util.regex包. 可粗略估计一下,除了偶尔用Linux的外,其他Linu x ...