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

最简单的首先就是使用管道了:

 # Read from the file file.txt and output the tenth line to stdout.
tail -n+ file.txt | head -n1

先倒序显示第一行到最后一行,然后使用head 来显示第一行。

LeetCode OJ: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. [Bash]LeetCode195. 第十行 | Tenth Line

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

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

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

  6. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  7. Tenth Line

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

  8. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  9. 195 Tenth Line

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

随机推荐

  1. 解决日志unicode编码问题

    Xcode打印日志里如果有汉字,有时会以Unicode编码形式展示,另需工具转码,降低了开发的效率,未解决这一问题,简便的解决方法是 pod 'HYBUnicodeReadable' 这个第三方库很好 ...

  2. shell进阶教程

    背景:就自己常用的shell脚本写作风格,总结了一些知识点.也是作为交接工作的一部分文档.部分内容单独写 #!/bin/sh # shell脚本进阶教程 # 1.常用知识点:变量设置/日期设置/格式化 ...

  3. (转)C#自制Web 服务器开发:用C#开发自己的Web服务器

    当输入:127.0.0.1:5050 GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: zh- ...

  4. 一键安装 zabbix 3.0 版本 脚本

    原文地址: http://blog.csdn.net/u012449196/article/details/53859068 本文修改了原文中的部分错误,此脚本适用于zabbix 2.0 或 3.0 ...

  5. KindEditor ctrl+v添加图片功能

    原理: 监听粘贴事件(paste) 获取粘贴版数据,读取到图片数据流进行加载base64 传到后台服务端直接输出为图片文件保存后返回图片读取路径插入编辑器中 /** * 获取编辑器对象 */ wind ...

  6. java for语句执行顺序

    public class test{ public static void main(String[] args) {          int i=0;          for(printChar ...

  7. NAT模式下远程连接centos6虚拟机与虚拟机网络配置

    最近装了centos,但是没有网络,也无法远程连接.关键是虚拟机中没有ip地址. 网上方法很多,但是每个人情况不一样,所以不尽适用. 1.解决这个问题,首先保证你的vmware的dhcp服务和net服 ...

  8. 拓扑排序 - hdu 1285(普通和优先队列优化)

    2017-09-12 19:50:58 writer:pprp 最近刚开始接触拓扑排序,拓扑排序适用于:无圈图的顶点的一种排序, 用来解决有优先级别的排序问题,比如课程先修后修,排名等. 主要实现:用 ...

  9. ACM输入函数测试 - scanf cin 优化的输入

    2017-08-27 10:26:19 writer:pprp 进行测试如下四种输入方式: 1.scanf 2.cin 3.用了ios::sync_with_stdio(false);的cin 4.自 ...

  10. Gym - 100712B Rock-Paper-Scissors

    https://vjudge.net/problem/Gym-100712B 题意: 石头剪刀布游戏. 给出一个玩家n局的出的顺序,现在另一个是这样出的,X+Y+Z=n,在前X轮出石头,中间Y轮出布, ...