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. WPF 集合分组排序

    <Window x:Class="ViewExam.MainWindow"        xmlns="http://schemas.microsoft.com/w ...

  2. js 注册事件

    <!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  3. c# Ajax后台动态分页

    创建WebPager类 public static class WebPager { public static string WebPagerAjax(string Idn, bool IsShor ...

  4. c# SQLHelper总汇

    /// <summary> /// The SqlHelper class is intended to encapsulate high performance, /// scalabl ...

  5. Android零基础入门第58节:数值选择器NumberPicker

    原文:Android零基础入门第58节:数值选择器NumberPicker 上一期学习了日期选择器DatePicker和时间选择器TimePicker,是不是感觉非常简单,本期继续来学习数值选择器Nu ...

  6. Android零基础入门第47节:自动完成文本框AutoCompleteTextView

    原文:Android零基础入门第47节:自动完成文本框AutoCompleteTextView 上一期学习的Spinner的使用,掌握的怎么样?本期一起来学习AutoCompleteTextView的 ...

  7. 建立Linux计划命令crontab

    crontab翻译:排程,命令 crontab从输入设备输入命令,并将其放入crontab文件,供守护进程crond读取并执行,crond在后台每一分钟执行一次 crontab -e:创建计划命令,进 ...

  8. <第三方>TGRefreshO按照QQ的刷新方式下拉刷新

    一 .使用方法:   刷新机制,类似QQ一样的刷新机制,弹簧.橡皮筋下拉刷新控件,类似QQ下拉刷新效果,同时支持其他样式:   首先写上这一句(必须的)   #import <TGRefresh ...

  9. 利用Rsync同步工具上传、删除目标文件

    Rsync是文件备份工具,当然也可以当做传输工具,管理远程服务器的文件 上传 rsync -avzP --progress --port 9106 /path/.../指定文件 root@192.16 ...

  10. 网络基础与FTP准备

    一网络基础 1.端口: 端口是为了将同一台电脑上的不同程序进行隔离 (IP是在找电脑,端口是在找电脑上的程序) 实例: MySQL是一个软件,帮助我们在硬盘上进行操作,默认端口是3306 Redis是 ...