题目大意:给一个多行的文件,让你写一段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相关推荐

  1. [Bash]LeetCode195. 第十行 | Tenth Line

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  2. LeetCode: 195. Tenth Line

    LeetCode: 195. Tenth Line 题目描述 Given a text file file.txt, print just the 10th line of the file. Exa ...

  3. 195. Tenth Line打印第十行Bash

    给定一个文本文件file.txt,仅打印文件的第10行. file.txt具有以下内容: Output: Line 10 注意: 1.如果文件少于10行,应该输出什么? 2.至少有三种不同的解决方案. ...

  4. LeetCode 195. Tenth Line (shell)

    描述 打印文件的第十行内容 解决 迭代 # Read from the file file.txt and output the tenth line to stdout count=1 cat fi ...

  5. (转载)输出文件的指定行

    Preface 最近我不是开始学Linux系统了吗= =,说真的,感觉自己有点蠢= =最近新弄了个QQ号,用来应对闲杂事情,然后突然就想加个Linux相关的群,来谈谈人生,结果问的第一个问题就把我难到 ...

  6. python2和pytho3切换_python2和pytho3切换_Python2和Python3共存安装

    PAT 1044. 火星数字(20) 火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly ...

  7. leetcode 的shell部分4道题整理

    对shell的某些细节还不是十分熟悉,借鉴了好多别人的东西 1. Word Frequency 此题很简单,只要能排序就可以 cat words.txt |tr -s " " &q ...

  8. LeetCode 简单算法题

    使用Nodejs 抓取的LeetCode 简单算法题  一步一步来,先攻破所有简单的题目,有些题目不适合使用JS解决,请自行斟酌 Letcode 简单题汇总 104. Maximum Depth of ...

  9. LeetCode 从零单刷个人笔记整理(持续更新)

    更新至2020.2.23 github:https://github.com/ChopinXBP/LeetCode-Babel 本人博客用于个人对知识点的记录和巩固. 用几乎所有可行的方法进行了实现和 ...

最新文章

  1. 《学习opencv》笔记——矩阵和图像处理——cvMinManLoc,cvMul,cvNot,cvNorm and cvNormalize...
  2. Memory Ordering
  3. 【Linux】一步一步学Linux——expr命令(265)
  4. iOS开发月报#10|201904
  5. Linux各个目录的作用及内容
  6. 查看计算机80端口,电脑win10 80端口被占用的检测和解决方法
  7. hadoop在ubuntu上的安装流程
  8. linux脚本取消空格,Shell去除空格和空行的方法
  9. excel使用教程_excel表格中页面布局下的分页符使用教程,以及使用excel宏vba批量插入分页符...
  10. 解决Ubuntu19.04下网易云音乐打不开的问题
  11. android 恢复出厂设置 时间,安卓恢复出厂设置
  12. 小飞鱼-致远OA 搭建借还款应用之选择借款 增加列显示
  13. [MySQL远程备份策略举例]
  14. MATLAB 绘制平行六面体
  15. MySQL自动删除指定时间以前的记录
  16. vmware安装openEuler+基本环境部署
  17. 电影《流浪地球》的一些有趣的细节
  18. 简单说说NVMe 2.0协议
  19. VMware 虚拟化套件
  20. python3安装mysql模块_python3操作MySQL的模块pymysql

热门文章

  1. 【程序员基础必备】计算机组成原理概念大全
  2. 酒店客房管家系统—贴牌oem定制开发商业模式详解
  3. 【陈老板赠书活动 - 03期】- 【代码整洁之道】
  4. 工业制造应用计算机智能的意义,机电一体化技术在智能制造的意义
  5. IBOX NFT 数字藏品价格 监控 工具 科技
  6. STC12C5A60S2实现PT100传感器分段高精度测温
  7. CF MySQL Service BOSH部署
  8. 干货!用C语言画一个小猪佩奇(附源码),针不戳!
  9. Android蓝牙4.0ble,蓝牙4.0(包含BLE)简介
  10. C++内存管理+模板入门知识点