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 发布文章使用:只允许注册用户才可以访问!