How to view a range of lines?

0144

To view a range of lines from a file, you can use the sed command or the head and tail commands in combination. Here are both methods:

Using sed

To view a specific range of lines, you can use the following sed command:

sed -n 'start_line,end_line p' filename.txt

Replace start_line and end_line with the line numbers you want to view, and filename.txt with the name of your file. For example, to view lines 10 to 20:

sed -n '10,20p' filename.txt

Using head and tail

You can also combine head and tail to achieve the same result. For example, to view lines 10 to 20:

head -n 20 filename.txt | tail -n 11

This command first gets the first 20 lines of the file and then pipes that output to tail, which retrieves the last 11 lines (lines 10 to 20).

Choose the method that best fits your needs!

0 Comments

no data
Be the first to share your comment!