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. 把Win10变成Mac OS:比任何美化主题都好用的工具

    摘要:把Win10变成Mac OS:比任何美化主题都好用的工具 - 这是一款真正意义上的把Windows变成MacOS的软件,不用更换主题,不用修改Dll,直接是程序接管了Explorer,比任何美化 ...

  2. 阿姆达尔定律 Amdahl's law

    Amdahl's law - Wikipedia https://en.wikipedia.org/wiki/Amdahl%27s_law 阿姆达尔定律(英语:Amdahl's law,Amdahl' ...

  3. 理解前端模块概念:CommonJs与ES6Module

    前言 现代前端开发每时每刻都和模块打交道.例如,在项目中引入一个插件,或者实现一个供全局使用组件的JS文件.这些都可以称为模块. 在设计程序结构时,不可能把所有代码都放在一起.更为友好的组织方式时按照 ...

  4. Mycat 配置文件解析

    Mycat 配置文件解析 一.server.xml 二.schema.xml 2.1 schema.xml文件中配置的参数解释 2.1.1 DataHost 2.1.2 DataNode 2.1.3 ...

  5. 深信服edr控制中心漏洞——代码执行

    第一处代码执行 文件:tool/php_cli.php第64行

  6. spark SQL (一)初识 ,简介

    一, 简介 Spark SQL是用于结构化数据处理的Spark模块.与基本的Spark RDD API不同,Spark SQL提供的接口为Spark提供了关于数据结构和正在执行的计算的更多信息.在内部 ...

  7. HDU4622 Reincarnation【SAM】

    HDU4622 Reincarnation 给出一个串,每次询问其一个子串有多少不同的子串 按每个后缀建立\(SAM\)不断往后加字符,然后记录答案,查询的时候直接用即可 //#pragma GCC ...

  8. Educational Codeforces Round 88 (Rated for Div. 2) A. Berland Poker(数学)

    题目链接:https://codeforces.com/contest/1359/problem/A 题意 $n$ 张牌可以刚好被平分给 $k$ 个人,其中有 $m$ 张 joker,当一个人手中的 ...

  9. 【bzoj 1190】梦幻岛宝珠(DP)

    这题是在01背包问题的基础上,扩充了重量,需要用时间换空间. 思路: 1.仔细看题,注意到重量wi为a*2^b(a<=10,b<=30),很容易想到要按 b 分开做背包的DP.接下来的重点 ...

  10. Java 窗口 绘制图形 #1

    写在前面: editplus换成eclipse了 Sketchpad要钱,买不起 自己搞(rua) by emeralddarkness 建立了一个平面直角坐标系 两个变元x,y,参数i 实现了以下功 ...