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.
Q.describe:use bash to print the tenth line of file.txt which is provide by the question  setter.
Solution:

awk 'NR == 10' file.txt
/*
awk [-F  field-separator]  'commands'  input-file(s) 
*/
Detail describe of awk in bash,please click in:
https://www.cyberciti.biz/faq/bash-scripting-using-awk/ Comment: this is my first blog article,if there are something wrong in the article,please point out,thanks.

Leetcode 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. 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] 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 ...

  4. [LeetCode] Tenth Line 第十行

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

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

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

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

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

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

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

  8. Tenth Line

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

  9. LeetCode 562. Longest Line of Consecutive One in Matrix(在矩阵中最长的连续1)$

    Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horiz ...

随机推荐

  1. Entity States

    Added. The entity does not yet exist in the database. The SaveChanges method must issue an INSERT st ...

  2. BackgroundWorker使用

    using System.ComponentModel; private BackgroundWorker worker;  worker = new BackgroundWorker(); work ...

  3. IOS开发之把 JSON 数据转化成 Arrays 或者 Dictionaries

    1 前言通过 NSJSONSerialization 这个类的 JSONObjectWithData:options:error:方法来实现,把JSON 数据解析出来放在数据或者字典里面保存. 2 代 ...

  4. 如何将svg转换为xaml

    原文:如何将svg转换为xaml 1 下载Inkscape 2 用Inkscape打开svg,另存为xaml 注意:复杂的svg图转换完会出现类似下面的xaml,wpf/silverlight是无法解 ...

  5. C++和QML混合的QT程序调试方法

    以前调试只是QML或者只是C++的QT程序很简单,断点打上,直接debug按钮一点,喝一口水,自然就停在断点了. 这次遇到C++和QML混合的程序,把CONFIG+=declarative_debug ...

  6. 伪类&伪元素

    刚开始学习伪类和伪元素的时候,觉得好混乱呀,分不清有什么区别,用的时候也没注意对比.现在总结一下他们的区别吧. w3c中对它们的定义分别为: css伪类用于向某些选择器添加特殊的效果. css伪元素用 ...

  7. EasyUI 实现编辑功能,给Combobox 赋值

    1: <input id="RequestType" name="RequestType" class="easyui-combobox&quo ...

  8. eval 未将对象引用到对象实例

    1.Eval("No") == null ? "" : Convert.ToString(Eval("NO"))

  9. 创建第一个ASP.NET MVC项目

    创建 新建->项目->展开Web->ASP.NET Web应用程序->MVC->确认 ASP.NET MVC应用程序的目录结构 /Controllers该目录保存处理UR ...

  10. QAbstractItemView为截断的项显示ToolTip(使用事件过滤)

    在Qt中想要为QAbstractItemView中长度不够而使得内容被截断的项显示ToolTip,Qt官网有一篇文章介绍使用事件过滤器来显示太长的项,但是没有涵盖图标的情况.显示列头项太长的情况等等, ...