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 ...
随机推荐
- Bitter.Core系列十:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore 之 Log 日志
Bitter 框架的 Log 全部采用 NLog 日志组件.Bitter.Core 的 执行语句的日志记录 Nlog 日志级别为:info. 如果想要查看Bitter.Core 的执行SQL,先要去 ...
- 现有以下关系型数据库中的表(见表4-20表4-21和表4-22),要求将具转换为适合Hbase存储的表并插入数据。
① createTable(String tableName, String[] fields) 创建表,参数tableName为表的名称,字符串数组fields为存储记录各个域名称的数组.要 求当H ...
- javamail发送邮件,支持yahoo,google,163.com,qq.com邮件发送
https://www.iteye.com/blog/fangyunfeng-1847352 https://blog.csdn.net/weixin_38465623/article/details ...
- ftp协议服务器与tinyhttp服务demo
https://www.jianshu.com/p/fb9fcb69efc9 ....... https://www.jianshu.com/p/e9a2e0755496 ============== ...
- FFT,NTT 笔记
FFT 简介 FFT是干啥的?它是用来加速多项式乘法的.我们平时经常求多项式乘法,比如\((x+1)(x+3)=(x^2+4x+3)\).假设两个式子都是\(n\)项(不足的补0),那朴素的算法是\( ...
- CODEVS 2542单词__fail树
2542 单词 2013年省队选拔赛天津市队选拔赛 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 小张最近在忙毕 ...
- SpringMVC听课笔记(十一:国际化)
1. 关于国际化 -- 在页面上根据浏览器的语言设置情况对文本(不是内容),时间,数值进行本地化处理 使用JSTL的fmt标签 -- 可以在bean中获取国际化资源文件 Locale对应的消息 在be ...
- XCTF-phoenix100
前期工作 查壳无壳,界面是普通的输入flag点击验证 逆向分析 文件结构只有一个MainActively,查看MainActively代码 public class MainActivity exte ...
- (二)基于shard-jdbc中间件,实现数据分库分表
基于shard-jdbc中间件,实现数据分库分表 Sharding-JDBC简介 Sharding配置示意图 1.水平分割 1.1 水平分库 1.2 水平分表 2.Shard-jdbc中间件 2.1 ...
- Java根据路径获取文件内容
文章目录 一.思路 二.实现 给出一个资源路径.然后获取资源文件信息,常见三种方式:①网络地址 ②本地绝对路径 ③本地相对路径 一.思路 首先,给出一个string表示资源文件的标识,如何判断是网络中 ...