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. Advanced Go Concurrency Patterns

    https://talks.golang.org/2013/advconc.slide#5 It's easy to go, but how to stop? Long-lived programs ...

  2. muduo 网络库的整体架构图和一个简化版本的架构设计

    https://blog.csdn.net/adkada1/article/details/54342275 简析 https://blog.csdn.net/amoscykl/article/det ...

  3. 使用Robo 3T操作MongoDB数据库

    安装Robo 3T连接MongoDB数据库教程:https://blog.csdn.net/baidu_39298625/article/details/98845789 在IDEA中用三个jar包链 ...

  4. 【算法】深度优先搜索(dfs)

    突然发现机房里有很多人不会暴搜(dfs),所以写一篇他们能听得懂的博客(大概?) PS:万能 yuechi ---- 大法师怎么能不会呢?! 若有错误,请 dalao 指出. 前置 我知道即使很多人都 ...

  5. HTML5 使用浏览器内置数据库之 indexedDB

    indexedDB是H5规范里的浏览器内置数据库,是nosql数据库的一种.因为另一种数据库Web SQL不再受W3C支持,所以还得学习下这个. 基本情况 兼容性:ie11及以上都支持, W3C是这么 ...

  6. 反弹SHELL介绍及原理

    如果我们需要到服务器上执行 Shell 命令,但是因为防火墙等原因,无法由客户端主动发起连接的情况,就可以使用反弹 Shell 来满足登陆和操作的需求. 什么是反弹Shell 正常情况下,我们登陆服务 ...

  7. Java——I/O操作之拷贝文件

    功能描述: 利用文件输入输出流编写一个实现文件拷贝的程序,源文件名和目标文件名通过控制台输入. public static void main(String[] args) { Scanner in= ...

  8. PHP-数组相关知识总结

    PHP-数组相关知识总结 (一)数组创建 //创建数组(php5.4 起可以使用短数组定义语法,用 [] 替代 array()) <?php$array = array(    "fo ...

  9. javascript脚本何时会被执行

    javascript脚本可以嵌入在html内的任意地方,但它何时被调用呢?当浏览器打开HTML文件后,会直接运行不是声明函数的脚本或通过事件调用脚本函数,下面分析这几种情况. 1.浏览器在打开页面时执 ...

  10. 2019牛客暑期多校训练营(第五场)C - generator 2 (BSGS)

    题目链接 题意: 给定\(n,x_0,a,b,p\),有递推式\(x_i = (a \cdot x_{i-1} +b)\%p\). 有\(Q\)个询问,每次询问给定一个\(v\),问是否存在一个最小的 ...