LeetCode #195 Tenth Line 第十行

195 Tenth Line 第十行

Description:
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.

题目描述:
给定一个文本文件 file.txt,请只打印这个文件中的第十行。

示例:

假设 file.txt 有如下内容:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

你的脚本应当显示第十行:

Line 10

思路:

awk命令

代码:
Bash:

awk -F: "NR==10{print}" file.txt
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,959评论 0 23
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 2,936评论 0 0
  • 192. Word Frequency Write a bash script to calculate the...
    01_小小鱼_01阅读 370评论 0 0
  • 过完年我准备换工作,到目前我也面试了不少公司也经历了不少事情,写下来希望对大家有些帮助。 先说我现在的公司,老大挽...
    小鱼嘻嘻阅读 1,285评论 20 19