欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Leetcode 195 Tenth Line

程序员文章站 2022-04-24 10:20:12
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has the following content: Your script should output t ......

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.