how to show one or more lines of a file in linux command

To show one line or more lines of a file, here are two functions for linux command.

1. sed command

show one line of a file

sed  -n 3p  file  # output the 3rd line of file

show more lines of a file

sed  -n 3,10p  file  # output the 3rd to 10th lines of file

2. head & tail

show one line of a file

head -n 3  file | tail -n 1  # output the 3rd line of file

show more lines of a file

head -n 10  file | tail -n 7  # output the 3rd to 10th lines of file

原创文章,作者:ifee,如若转载,请注明出处:https://www.ifee.win/blog/2021/05/15/how-to-show-one-or-more-lines-of-a-file-in-linux-command/

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注