[Bash]LeetCode195. 第十行 | Tenth Line
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/10180443.html
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
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
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
说明:
1. 如果文件少于十行,你应当输出什么?
2. 至少有三种不同的解法,请尝试尽可能多的方法来解题。
4ms
1 # Read from the file file.txt and output the tenth line to stdout. 2 sed -n 10p file.txt
4ms
1 # Read from the file file.txt and output the tenth line to stdout. 2 awk 'NR==10' file.txt
8ms
1 # Read from the file file.txt and output the tenth line to stdout. 2 { cat file.txt; for (( i = 1; i <= 10; ++i)); do echo ; done } | head -n 10 | tail -n 1
12ms
1 # Read from the file file.txt and output the tenth line to stdout. 2 3 sed 's/\\n/\ 4 /g' file.txt | awk 'NR==10{print}'
转载于:https://www.cnblogs.com/strengthen/p/10180443.html
[Bash]LeetCode195. 第十行 | Tenth Line相关推荐
- 195. Tenth Line打印第十行Bash
给定一个文本文件file.txt,仅打印文件的第10行. file.txt具有以下内容: Output: Line 10 注意: 1.如果文件少于10行,应该输出什么? 2.至少有三种不同的解决方案. ...
- LeetCode 195. Tenth Line (shell)
描述 打印文件的第十行内容 解决 迭代 # Read from the file file.txt and output the tenth line to stdout count=1 cat fi ...
- Tenth Line
题目大意:给一个多行的文件,让你写一段shell脚本把文件的第10行输出来. 方法一: # Read from the file file.txt and output the tenth line ...
- LeetCode: 195. Tenth Line
LeetCode: 195. Tenth Line 题目描述 Given a text file file.txt, print just the 10th line of the file. Exa ...
- LeetCode 从零单刷个人笔记整理(持续更新)
更新至2020.2.23 github:https://github.com/ChopinXBP/LeetCode-Babel 本人博客用于个人对知识点的记录和巩固. 用几乎所有可行的方法进行了实现和 ...
- bash和sed简要介绍和相关范例
一.bash 中如何进行条件测试: 有三种类型的测试:整数测试.字符串测试.文件测试 1.整数测试: -eq 左边的值是否等于右边 -gt 左边的值是否大于右边 -ge 左边的值是否大于等 ...
- linux shell #[感叹号]/bin/bash 是什么意思?
垃圾CSDN,标题里感叹号都发不出来! 文章目录 #!/bin/bash简介 1)`#!/bin/bash`只能放在第一行,如果后面还有`#!`,那么只能看成是注释. 2)#!后面的路径一定要正确,不 ...
- shell脚本while read line的使用
#### 题目要求 计算文档a.txt中每一行中出现的数字个数并且要计算一下整个文档中一共出现了几个数字.例如a.txt内容如下: 12aa*lkjskdj alskdflkskdjflkjj 我们脚 ...
- 由一道bash jail题引出的琐事@_@
关键词:Terminal devices.shell.stdio 题目入口: (需要注册) root@kali:~# ssh level1@24.37.41.154 -p 1016 level1@24 ...
最新文章
- 病毒的灵魂拷问(绝对原创)
- swift:使用协议protocol设置颜色,UIImage的切圆角ImageWithCornerRadius
- MacOS开发必备工具brew,安装nginx反向代理,替代linux工具 apt-get和 yum...
- springboot使用rabbitMQ(带回调)
- linux ftp 后台执行,Linux环境CENTOS下apache-ftpserver搭建配置及后台启动
- python判断字符串里的字符_python 判断检测字符串中是否包含指定字符或字符串(比如:?)...
- 需求分析三层境界,你到哪层了?
- oracle添加序列器,Oracle 建表,添加主外键,序列,触发器
- Netty 5.X 官方指南翻译版4
- 南京大学信号与系统851考研上岸经验分享
- stm32蜂鸣器程序
- android mvp知乎,安卓日记——MVP重构知乎日报
- windows开发机做路由器映射大坑
- kaka启动出现:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000c00000, 1073,0)
- nuc7 android x86,OpenWrt X86 X64 NUC刷写教程
- SQL调优指南笔记6:Explaining and Displaying Execution Plans
- sx1278组网-子设备
- 解压软件Bandizip
- Android自定义控件开发入门与实战(7)SVG动画,android底层架构
- 什么是GC,为什么需要GC?