i'm trying to display the 3rd to the 7th line from a file but i get nothing displayed in the terminal i'm using this command :
head -n 7 /etc/passwd | tail -n +3
i want the result be seen in the terminal .
You can try this way
head -n 7 /etc/passwd | tail -n 5
For example :
seq 20 | head -n 7 | tail -n 5
Output :
3
4
5
6
7
Explanation :
head -n 7 -- print the first 7 lines ( so 1..7 printed)
tail -n 5 -- print last 5 lines ( so skipped first two lines 3..7 printed )
head -n 7 /etc/passwd | tail -n +3
Seems to do exactly what you want it to do for me. Have you verified the contents of /etc/passwd? If you do not have permission to read the file or it is empty you will get no output.
I would check other places in the script. Change the first line of your script to:
#!/bin/bash -v
to have it echo the commands so you can make sure what you think is being executed actually is.
What do you get than ? Show the file output, but choose another file ;)
It sometimes helps to just change commands, try with either HEAD or TAIL twice, to come to the same result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.