Tenth Line
题目大意:给一个多行的文件,让你写一段shell脚本把文件的第10行输出来。
方法一:
# Read from the file file.txt and output the tenth line to stdout.
count=0
while read line && [ $count -le 10 ]
docount=$[$count+1]if [ $count -eq 10 ]thenecho $lineexitfi
done < file.txt
方法二:
# Read from the file file.txt and output the tenth line to stdout.
sed -n '10p' file.txt
方法三:
# Read from the file file.txt and output the tenth line to stdout.
awk '{if(NR==10) print $0}' file.txt
方法四:(方法三的简化)
# Read from the file file.txt and output the tenth line to stdout.
awk 'NR==10' file.txt
Tenth Line相关推荐
- [Bash]LeetCode195. 第十行 | Tenth Line
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- LeetCode: 195. Tenth Line
LeetCode: 195. Tenth Line 题目描述 Given a text file file.txt, print just the 10th line of the file. Exa ...
- 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 ...
- (转载)输出文件的指定行
Preface 最近我不是开始学Linux系统了吗= =,说真的,感觉自己有点蠢= =最近新弄了个QQ号,用来应对闲杂事情,然后突然就想加个Linux相关的群,来谈谈人生,结果问的第一个问题就把我难到 ...
- python2和pytho3切换_python2和pytho3切换_Python2和Python3共存安装
PAT 1044. 火星数字(20) 火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly ...
- leetcode 的shell部分4道题整理
对shell的某些细节还不是十分熟悉,借鉴了好多别人的东西 1. Word Frequency 此题很简单,只要能排序就可以 cat words.txt |tr -s " " &q ...
- LeetCode 简单算法题
使用Nodejs 抓取的LeetCode 简单算法题 一步一步来,先攻破所有简单的题目,有些题目不适合使用JS解决,请自行斟酌 Letcode 简单题汇总 104. Maximum Depth of ...
- LeetCode 从零单刷个人笔记整理(持续更新)
更新至2020.2.23 github:https://github.com/ChopinXBP/LeetCode-Babel 本人博客用于个人对知识点的记录和巩固. 用几乎所有可行的方法进行了实现和 ...
最新文章
- 《学习opencv》笔记——矩阵和图像处理——cvMinManLoc,cvMul,cvNot,cvNorm and cvNormalize...
- Memory Ordering
- 【Linux】一步一步学Linux——expr命令(265)
- iOS开发月报#10|201904
- Linux各个目录的作用及内容
- 查看计算机80端口,电脑win10 80端口被占用的检测和解决方法
- hadoop在ubuntu上的安装流程
- linux脚本取消空格,Shell去除空格和空行的方法
- excel使用教程_excel表格中页面布局下的分页符使用教程,以及使用excel宏vba批量插入分页符...
- 解决Ubuntu19.04下网易云音乐打不开的问题
- android 恢复出厂设置 时间,安卓恢复出厂设置
- 小飞鱼-致远OA 搭建借还款应用之选择借款 增加列显示
- [MySQL远程备份策略举例]
- MATLAB 绘制平行六面体
- MySQL自动删除指定时间以前的记录
- vmware安装openEuler+基本环境部署
- 电影《流浪地球》的一些有趣的细节
- 简单说说NVMe 2.0协议
- VMware 虚拟化套件
- python3安装mysql模块_python3操作MySQL的模块pymysql