开发者

Using head and tail to return the nth item from a file in Linux

开发者 https://www.devze.com 2023-03-06 22:01 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消