how to read the 10th line of a text using shell script All In One
how to read the 10th line of a text using shell script All In One
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
https://www.geeksforgeeks.org/head-command-linux-examples/
# head [ +-[number][lbcr] ] [file]
$ head -10 ./text.txt
tail
# tail [ +-[number][lbcr] ] [file]
$ tail -10 ./text.txt
https://www.geeksforgeeks.org/tail-command-linux-examples/
API docs
sed
、head
、tail
https://www.computerhope.com/unix/used.htm
https://www.computerhope.com/unix/uhead.htm
https://www.computerhope.com/unix/utail.htm
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/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13632297.html
未经授权禁止转载,违者必究!