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 ...
随机推荐
- Linux学习笔记14——使用fcntl实现文件锁定
期末考试快要来了,Linux学习进度一下拉下来许多.今天学习的是文件锁定,在Linux中,实现文件锁定的方法很多,例如fcntl和lockf.下面主要是fcntl的调用. fcntl函数的原型是:in ...
- TCP协议状态简介
原文出自:Vimer的程序世界 1.建立连接协议(三次握手)(1)客户端发送一个带SYN标志的TCP报文到服务器.这是三次握手过程中的报文1.(2) 服务器端回应客户端的,这是三次握手中的第2个报文, ...
- C语言学习_一个简单程序的解释与C学习方法概括
简单计算器程序示例: # include <stdio.h> //1.头文件 //2.加法函数 int add(int a,int b)//3.函数定义方式 { //4.函数体 retur ...
- mysql创建数据库(指定编码)
如下脚本创建数据库yourdbname,并制定默认的字符集是utf8. CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 CO ...
- Codeforces Beta Round #10 D. LCIS(DP&LCIS)
D. LCIS time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- nginx代理人server结合tomcat采用
相信非常多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那到底它有什么作用呢?可能非常多人未必了解. 说到反向代理,可能非常多人都听说,但详细什么是反向代理,非常多人预计就 ...
- Java基础知识强化之集合框架笔记31:集合之泛型类的概述和基本使用
1. 为什么会有泛型呢? (1)早期的Object类型可以接收任意的对象类型,但是在实际使用中,会有类型转换的问题,也存在这隐患,所以Java提供了泛型来解决这个安全问题. 2. 泛型类的使用: (1 ...
- 使用WebSocket构建实时WEB
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3795075.html ...
- Springmvc中@RequestParam传值中文乱码解决方案(转)
@RequestMapping(value={"/list"},method=RequestMethod.GET) @ResponseBody public DeviceList ...
- HDFS的Java客户端操作代码(查看HDFS下所有的文件存储位置信息)
1.查看HDFS下所有的文件存储位置信息 package Hdfs; import java.net.URI; import org.apache.hadoop.conf.Configuration; ...