Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract text between two line numbers [duplicate]

Tags:

linux

bash

sed

I am trying to extract the text between two specific line numbers using

sed 'startLine,endLined' myFile.txt

But somehow it keeps extracting from the begining of the file to endLine.

What is wrong here?

like image 207
Myh Avatar asked Jun 25 '26 17:06

Myh


1 Answers

You need to tell sed not to print all other lines but the ones you want.

 sed -n '123,234p' myFile.txt

The -n tells sed do not print lines scanned.
the 123,234 define the range of lines you are interested in
the p is the command to print the line.

This way it will only print the lines that match what you told it.

like image 117
Rob Avatar answered Jun 27 '26 09:06

Rob