leetcode 195. 第十行

红太狼 2022-10-23 00:53 197阅读 0赞

题目:

给定一个文本文件 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

思路:

参考

打 印 第 十 行 :sed -n ‘10p’ file.txt
打 印 一 到 十 行 :sed -n ‘1,10p’ file.txt
查 找 指 定 字 符 :grep -n ‘KeyWord’ file.txt
打印指定字符上下5行:grep -C 5 ‘KeyWord’ file.txt
打印指定字符上下N行:grep -A 100 -B 100 ‘KeyWord’ file.txt

代码实现:

  1. # Read from the file file.txt and output the tenth line to stdout.
  2. sed -n '10p' file.txt

运行结果:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L01fRXZl_size_16_color_FFFFFF_t_70

发表评论

表情:
评论列表 (有 0 条评论,197人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ABC 195 C

    不知道该怎么解释这道题,反正我不太会,感觉很帅 题意: ![5ea04594676f4a78a31bec299de61d1a.png][] Code: incl

    相关 章 可方向法

    基本思想:要求每一步迭代产生的搜索方向不仅对目标函数是下降方向,而且对约束函数来说是可行方向,即迭代点总是满足所有的约束条件。 本章内容转载自博主ML\: [Zouten