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的更多相关文章

  1. linux脚本错误: line *: [: missing `]',linux编写shell脚本时的注意点

    转载:https://www.cnblogs.com/bovenson/p/4548079.html 关于shell的一些注意点,粘贴自拉钩教育精选评论:测试开发核心技术 46 讲-->第6讲 ...

  2. SNMP 原理与实战详解

    原文地址:http://freeloda.blog.51cto.com/2033581/1306743 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法 ...

  3. cacti监控系统

    cacti 1. cacti安装 IP: 172.25.44.1 环境: Red Hat 6.5 镜像: rhel-server-6.5-x86_64-dvd.iso 火墙: /etc/init.d/ ...

  4. SNMP学习笔记之SNMP 原理与实战详解

    原文地址:http://freeloda.blog.51cto.com/2033581/1306743 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法 ...

  5. SNMP协议介绍

    SNMP协议介绍 一.什么是SNMP SNMP:“简单网络管理协议”,用于网络管理的协议.SNMP用于网络设备的管理.SNMP的工作方式:管理员需要向设备获取数据,所以SNMP提供了 “读”操作:管理 ...

  6. Net-SNMP(V3协议)安装配置笔记(CentOS 5.2)(转)

    原出处:http://blog.ihipop.info/2010/03/722.html 为了这颗仙人掌(cacti),我必须先部署(Net-SNMP), 同时我为了安全因素,也为了简便考虑,决定采用 ...

  7. Linux(8):linux三剑客sed和awk & Shell 编程(1)

    linux 三剑客 之 sed # sed 是什么? # sed : 字符流编辑器 Stream Editor: sed 擅长 替换.取行等 # sed 的功能与版本: 处理纯文本文件.日志.配置文件 ...

  8. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  9. Tenth Line

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

随机推荐

  1. Any race is a bug. When there is a race, the compiler is free to do whatever it wants.

    https://mp.weixin.qq.com/s/pVJiFdDDKVx707eKL19bjA 谈谈 Golang 中的 Data Race 原创 ms2008 poslua 2019-05-13 ...

  2. https://nginx.org/en/docs/http/request_processing.html

    https://nginx.org/en/docs/http/request_processing.html

  3. 在这个示例中,使用 watch 选项允许我们执行异步操作 (访问一个 API),限制我们执行该操作的频率,并在我们得到最终结果前,设置中间状态。这些都是计算属性无法做到的。

    在这个示例中,使用 watch 选项允许我们执行异步操作 (访问一个 API),限制我们执行该操作的频率,并在我们得到最终结果前,设置中间状态.这些都是计算属性无法做到的.

  4. P6584 重拳出击

    写在前面 来给 zrm 大佬的题写一篇题解. 这题代码实现难度不高,但是比较锻炼思维,而且应该有不少种解法.着实是一道质量很高的题目. 算法思路 首先呢,显然当小 Z 向当前节点的一棵子树走去时,这棵 ...

  5. tricks - 实现

    笔记总页面 目录 负下标 动态开点 花括号 负下标 有的时候我们需要存一些负的东西,比如我就只要一个 \(-1\),或者说值域是 \([-10^6,10^6]\),而我懒得写平移 (写平移不仅麻烦,而 ...

  6. Java8种排序算法学习

    冒泡排序 public class test { public static void main(String[] args) { // TODO Auto-generated method stub ...

  7. Centos搭建Hive

    Centos搭建Hive 一.Hive简介 二.安装Hive 2.1hive下载 2.2上传解压 2.3配置hive相关的环境变量 三.Mysql 3.1安装mysql connector 3.2 将 ...

  8. (13)Linux文件系统的优缺点

    通过文件系统的方式来组织磁盘存储和数据管理.有以下几个方面的好处. 数据的读取.管理操作变得简单 文件系统给用户提供了一个简单的操作界面,用户可以通过对文件系统的简单操作,实现对磁盘的管理.虽然 Li ...

  9. httprunner(4)录制生成测试用例

    前言 写用例之前,我们应该熟悉API的详细信息.建议使用抓包工具Charles或AnyProxy进行抓包. har2case 我们先来了解一下另一个项目har2case 他的工作原理就是将当前主流的抓 ...

  10. jQuery插件Validate

    一.导入js库 <script type="text/javascript" src="<%=path %>/validate/jquery-1.6.2 ...