how to read the 10th line of a text using shell script
how to read the 10th line of a text using shell script
shell script / bash script
question

https://leetcode.com/problems/tenth-line/
solutions
https://leetcode.com/submissions/detail/392695695/
$ sed -n 10p file.txt
$ bash file.sh | sed -n '10 p'

sed
https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/
file.sh
echo "Line 1"
echo "Line 2"
echo "Line 3"
echo "Line 4"
echo "Line 5"
echo "Line 6"
echo "Line 7"
echo "Line 8"
echo "Line 9"
echo "Line 10"
# bash file.txt | sed -n '10 p'
# bash file.sh | sed -n '10 p'
# zsh file.txt | sed -n '10 p'
# zsh file.sh | sed -n '10 p'
Error
# zsh file.txt | sed -n '10 p'
$ zsh file.txt | sed -n '10 p'
# bash file.txt | sed -n '10 p'
$ bash file.txt | sed -n '10 p'

OK
# zsh file.sh | sed -n '10 p'
$ zsh file.sh | sed -n '10 p'
# bash file.sh | sed -n '10 p'
$ bash file.sh | sed -n '10 p'

awk
https://www.geeksforgeeks.org/awk-command-unixlinux-examples/
$
head / tail
https://www.geeksforgeeks.org/head-command-linux-examples/
https://www.geeksforgeeks.org/tail-command-linux-examples/
$
$
refs
https://unix.stackexchange.com/questions/29878/can-i-access-nth-line-number-of-standard-output
https://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file
https://www.geeksforgeeks.org/write-bash-script-print-particular-line-file/
http://bigdatums.net/2016/02/22/3-ways-to-get-the-nth-line-of-a-file-in-linux/
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
how to read the 10th line of a text using shell script的更多相关文章
- linux脚本错误: line *: [: missing `]',linux编写shell脚本时的注意点
转载:https://www.cnblogs.com/bovenson/p/4548079.html 关于shell的一些注意点,粘贴自拉钩教育精选评论:测试开发核心技术 46 讲-->第6讲 ...
- SNMP 原理与实战详解
原文地址:http://freeloda.blog.51cto.com/2033581/1306743 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法 ...
- cacti监控系统
cacti 1. cacti安装 IP: 172.25.44.1 环境: Red Hat 6.5 镜像: rhel-server-6.5-x86_64-dvd.iso 火墙: /etc/init.d/ ...
- SNMP学习笔记之SNMP 原理与实战详解
原文地址:http://freeloda.blog.51cto.com/2033581/1306743 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法 ...
- SNMP协议介绍
SNMP协议介绍 一.什么是SNMP SNMP:“简单网络管理协议”,用于网络管理的协议.SNMP用于网络设备的管理.SNMP的工作方式:管理员需要向设备获取数据,所以SNMP提供了 “读”操作:管理 ...
- Net-SNMP(V3协议)安装配置笔记(CentOS 5.2)(转)
原出处:http://blog.ihipop.info/2010/03/722.html 为了这颗仙人掌(cacti),我必须先部署(Net-SNMP), 同时我为了安全因素,也为了简便考虑,决定采用 ...
- Linux(8):linux三剑客sed和awk & Shell 编程(1)
linux 三剑客 之 sed # sed 是什么? # sed : 字符流编辑器 Stream Editor: sed 擅长 替换.取行等 # sed 的功能与版本: 处理纯文本文件.日志.配置文件 ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- Tenth Line
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
随机推荐
- Prometheus 初探和配置(安装测试)
本文大纲: • Prometheus 官⽹下载• Prometheus 开始安装• Prometheus 启动运⾏• Prometheus 基本配置⽂件讲解• 安装第⼀个exporter => ...
- MySQL常见优化
MySQL常见优化 1.操作符优化 1.1<> 操作符(不等于) 1.2LIKE优化 1.3in,not in,exists与not exists 1.3.1in和exists 2.whe ...
- SpringMVC请求参数的获取方式
一.GET请求参数获取 1. 通过HttpServletRequest获取参数 2. 直接方法参数获取 3. RequestParam注解方式获取请求参数 4. Bean方式获取参数 5. Model ...
- Aruba无线控制器常用操作
初始配置 1.console到初始化的无线控制器上 Enter System name [Aruba7005]: Enter VLAN 1 interface IP address [172.16.0 ...
- MacOS Big Sur开HiDPI
我自己的环境: 开启hidpi的目的是为了让显示更加细腻,代价是缩小了显示范围. 自己在网上看了很多帖子,也尝试了几种,有些方法已经不再适合Big Sur系统了,所以本文提供一种可用的,在Big Su ...
- 【从零开始撸一个App】RecyclerView的使用
目标 前段时间打造了一款简单易用功能全面的图片上传组件,现在就来将上传的图片以图片集的形式展现到App上.出于用户体验考虑,加载新图片采用[无限]滚动模式,Android平台上我们优选Recycler ...
- Jenkins(2)docker容器中安装python3
前言 使用docker安装jenkins环境,jenkins构建的workspace目录默认是在容器里面构建的,如果我们想执行python3的代码,需进容器内部安装python3的环境. 进jenki ...
- CPU中的程序是怎么运行起来的
总述 最近一位朋友问我,开发的代码是怎么在芯片运行起来的,我就开始给他介绍代码的预编译.汇编.编译.链接然后到一般的文件属性,再到代码运行.但是大佬问了我一句,CPU到底是怎么执行到每一个逻辑的,就讲 ...
- 2019牛客暑期多校训练营(第三场) F.Planting Trees(单调队列)
题意:给你一个n*n的高度矩阵 要你找到里面最大的矩阵且最大的高度差不能超过m 思路:我们首先枚举上下右边界,然后我们可以用单调队列维护一个最左的边界 然后计算最大值 时间复杂度为O(n*n*n) # ...
- Equal Numbers Gym - 101612E 思维
题意: 给你n个数vi,你有k次操作.每一次操作你可以从n个数里面挑一个数,然后使得这个数乘于一个正整数.操作完之后,这n个数里面不同数的数量就是权值.你要使得这个值尽可能小. 题解: 如果a%b== ...