Using head and tail to return the nth item from a file in Linux
I'm pretty new to using Linux commands. So suppose I have a file with 100 thousand lines. Well suppose I want to get line 50,000. Is there a way I can give the shell a command to retrieve line 50,000 using head a开发者_如何学Gond tail commands?
The above examples can work, but there are other ways, like sed
for example:
% sed -n '50000p' filename
head -n 50000 FILENAME | tail -1
That should work. However this may not be the most efficient way of accessing the 50000th line
head -[linenumber] file | tail -1
head -n 50000 file_name | tail -n 1
Should work
精彩评论