[ LeetCode试题 ] 195 Tenth Line

Solution1:

cat file.txt | awk ‘{if(NR==10)print $0}‘

Solution2:

cat file.txt | sed -n ‘10p‘
时间: 2024-10-16 07:46:07

[ LeetCode试题 ] 195 Tenth Line的相关文章

Leetcode 195 Tenth Line

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

195 Tenth Line

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

LeetCode第195题---Tenth Line

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 [show hi

[LeetCode][Shell]Tenth Line

Tenth Line 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

[LeetCode] Tenth Line 第十行

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 [show hi

【leetcode~Shell】:Tenth Line

Tenth Line:https://leetcode.com/problems/tenth-line/ 题意:打印出一个文件的第10行. 问题涉及到几个点: 1.如何读取一个文件? 2.如何找到第10行? 3.如果文件是空的或者少于10行怎么办? 解法: 1.shell读取文件的一种方法: while read line do echo $line done < filename 2.用计数的方法找到第10行. 3.如果文件是空的或者少于10行,那么输出空. 代码: cnt=1 while r

Tenth Line

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 Hint: 1.

LeetCode Coins in a Line

There are n coins in a line. Two players take turns to take one or two coins from right side until there are no more coins left. The player who take the last coin wins. Could you please decide the first play will win or lose? 该题类似于下题: 箱子里面有一百个球,甲和乙分别

[Linux] 输出文件的指定行

1.获取第k行(以k=10为例) 要注意的是,如果文件包含内容不足10行,应该不输出. # Read from the file file.txt and output the tenth line to stdout. # 解法一,使用awk awk 'NR == 10' file.txt # 解法二,使用sed(个人测试结果:sed方法比awk快) sed -n '10p' file.txt # 解法三,组合使用tail与head tail -n+10 file.txt | head -n1