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. moco框架加入cookies

    一.带cookie信息的get请求 注意:cookie是放在request里的,一般登录的场景这些会用到 1.代码 2.接口管理工具添加 注意:cooike的域和路径都要添加 二.带cookie信息的 ...

  2. (007)每日SQL学习:将字符和数字分离

    with aa as ( select 'sad10' as data from dual union all select 'datf20' as data from dual union all ...

  3. GC 卡顿 优化 三色标记优势

    小结: 1. 三色标记的一个明显好处是能够让用户程序和 mark 并发的进行 Go GC 卡顿由秒级降到毫秒级以下:到底做了哪些优化? https://mp.weixin.qq.com/s/2BMGG ...

  4. 一文打尽端口复用 VS Haproxy端口复用

    出品|MS08067实验室(www.ms08067.com) 本文作者:Spark(Ms08067内网安全小组成员) 1.概述   Haproxy是一个使用c语言开发的高性能负载均衡代理软件,提供tc ...

  5. 向指定url发送Get/Post请求

    向指定url发送Get/Post请求 1.向指定url发送Get/Post请求 2.HttpUtil 工具类–向指定url发送Get/Post请求 1.向指定url发送Get/Post请求 impor ...

  6. 面向对象编程(UDP协议)

    UDP协议 UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联) 参考模型中一种无 ...

  7. ubuntu下scala下载+集成IDEA开发环境

    环境须知: ubuntu 16.04 scala 2.11.0 jdk 1.8.0 Idea 2016.3 JDK环境安装 (1)安装jdk, 注意scala很好的支持jdk 1.8 的jvm 编译环 ...

  8. java判断是否为整数

    /** * 判断是否为整数 * * @param str 传入的字符串 * @return 是整数返回true,否则返回false */ public static boolean isInteger ...

  9. dedecms万能SQL标签使用方法大全

    注意:dede_archives这是系统默认的数据库表,如果你修改过表前缀dede_,请自行更改表名.在以下示例的标签中,有一部分只写出了SQL语句,具体的完整标签写法请参考:织梦SQL标签调用方法. ...

  10. 浅谈Winform控件开发(一):使用GDI+美化基础窗口

    写在前面: 本系列随笔将作为我对于winform控件开发的心得总结,方便对一些读者在GDI+.winform等技术方面进行一个入门级的讲解,抛砖引玉. 别问为什么不用WPF,为什么不用QT.问就是懒, ...