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. ospf-lite runs over tcp / udp port 8899.

    draft-thomas-reed-ospf-lite-01 - ospf-lite https://tools.ietf.org/html/draft-thomas-reed-ospf-lite-0 ...

  2. DevOps运动的缘起 将DevOps想象为一种编程语言里面的一个接口,而SRE类实现了这个接口

     SRE vs DevOps:是敌是友? - DockOne.io http://www.dockone.io/article/5935   RE vs DevOps:是敌是友? [编者的话]网站可靠 ...

  3. Java 常见关键字总结:final、static、this、super!

    final,static,this,super 关键字总结 final 关键字 final关键字,意思是最终的.不可修改的,最见不得变化 ,用来修饰类.方法和变量,具有以下特点: final修饰的类不 ...

  4. Axure RP 9版本最新版授权码和密钥 亲测可用

    分享Axure RP 9版本最新版授权码和密钥 亲测可用 声明:以下资源的获取来源为网络收集,仅供学习参考,不作商业用途,如有侵权请联系博主删除,谢谢! 自新的Axure RP 9.0 Beta版发布 ...

  5. SSRF-Vulnerable-Lab靶场训练

    参考文章 SSRF-Vulnerable-Lab tag: #SSRF Ref: 1.file_get_content.php 提取并显示指定文件内容的应用程序代码 在编程语言中,有一些函数可以获取本 ...

  6. .htaccess 和 .user.ini

    .htaccess 仅能用于apache下,并且内容严格,不能有错误行,如:GIF89a .user.ini php 5.3.0开始引入,可设置除了:PHP_INI_SYSTEM 外的其他,包括(PH ...

  7. SpringMVC听课笔记(七:Restful CRUD)

    这章貌似没有什么可讲的,可以看GitHub工程代码: https://github.com/heyboom/SpringMVC_Rest_CRUD

  8. Mysql数据库版本高低引起的group by问题

    低版本的Mysql,group by限制性比较小,在进行group by时,select的对象可包含多个,但是换成高版本5.6以上好像,使用group by 以后,select的对象必须也已经被聚合, ...

  9. (6)dd命令安装Linux

    1.面对大批量服务器的安装,人们往往热衷于选择"无人值守安装"的方式,而此方式需要对服务器进行过多的配置,并不适合初学者. 无人值守安装(Kickstart),又称全自动安装,其工 ...

  10. 带撤销并查集 & 可持久化并查集

    带撤销并查集支持从某个元素从原来的集合中撤出来,然后加入到一个另外一个集合中,或者删除该元素 用一个映射来表示元素和并查集中序号的关系,代码中用\(to[x]\) 表示x号元素在并查集中的 id 删除 ...