Print certain lines of a file in Linux bash

Home > Search
  by

Let's say file.txt contains the following text.

~]# cat file.txt
Hello
World
How
are
you
today?

 

The sed command can be used to print certain lines of the file. In this example, lines 1 through 3 and line 6 are printed.

~]# cat file.txt | sed -n -e 1,3p -e 6p
Hello
World
How
today?

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments