2

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?

Myh
  • 95
  • 1
  • 9

3 Answers3

8

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.

Rob
  • 2,618
  • 2
  • 22
  • 29
2

Try sed -n 'startLine,endLined' myFile.txt

Sivakumar Tadisetti
  • 4,865
  • 7
  • 34
  • 56
withlimin
  • 21
  • 1
1

Another using awk:

$ seq 10 -1 1 | awk 'NR==3,NR==6'
8
7
6
5

seq 10 -1 1 outputs numbers from 10 down to 1. awk 'NR==3,NR==6' prints records between lines 3-6.

James Brown
  • 36,089
  • 7
  • 43
  • 59