leetcode:Tenth Line 【shell】

来源:互联网 发布:golang占位符 编辑:程序博客网 时间:2024/06/06 02:06

一、问题描述

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

二、问题分析

  1. shell整形变量操作,参考链接
  2. 按行读取文件,参考链接
  3. while循环,参考链接
  4. if判断,参考链接

三、shell代码

# Read from the file file.txt and output the tenth line to stdout.declare -i count=0 #声明count为整形变量cat file.txt | while read linedolet count++; #使count加1if [ $count -eq 10 ]; thenecho $linefidone
0 0
原创粉丝点击