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. jquery 显示图片

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  2. teamcity build web project arguments

    /p:Configuration=%system.Configuration%  => Release /p:DeployOnBuild=%system.DeployOnBuild%  => ...

  3. css3如何让div一直循环自转圈,附带:网络请求通知图片一直在转圈实例

    css3如何让div一直循环自转圈 代码如下: div{ -webkit-transition-property: -webkit-transform; -webkit-transition-dura ...

  4. texbox 禁用copy paster cut

    <TextBox CommandManager.PreviewExecuted="textBox_PreviewExecuted" ContextMenu="{x: ...

  5. RSACryptoServiceProvider加密解密签名验签和DESCryptoServiceProvider加解密

    原文:RSACryptoServiceProvider加密解密签名验签和DESCryptoServiceProvider加解密 C#在using System.Security.Cryptograph ...

  6. 使用Notepad++远程编辑Ubuntu上的源码

    简单搭建了在Windows上远程编辑Ubuntu Server 14.04上面源代码的环境,记录一下,给需要的人. Notepad++安装NppFTP 从插件菜单打开PluginManager,选中N ...

  7. PING[ARC2]: Heartbeat failed to connect to standby 'gqtzdb_dg'. Error is 16047

    Data Guard搭建完毕之后,执行开启归档路径2,结果发现不同步, SQL> alter system set log_archive_dest_state_2=enable; 查看错误日志 ...

  8. LINQ学习笔记(一)

    LINQ,语言集成查询(Language Integrated Query)是一组用于C#和Visual Basic语言的扩展. 它允许编写C#或Visual Basic代码以查询数据库相同的方法操作 ...

  9. WD-线程KTHREAD结构(WRK)

    线程是系统处理器调度的基本单元,而且线程调度是在内核层完成的,所以,KTHREAD 的许多域都跟Windows 的线程调度机制有关. 找到进程的线程可以使用!process 1 2 3 kd> ...

  10. CMake编译Widget UI Qt程序

    自从CMake被引入到KDE项目的编译系统中后,CMake的使用者日益增多,Qt也不例外,除了使用QMAKE编译Qt程序外,也可以使用CMake来编译Qt程序,并且CMake在使用上更灵活,特别是大型 ...