0

I have a large file containing 400K rows.

I have to select rows between 45,000 to 50,000.

I know I can write a have program and keep counting the rows and then select the lines between the interval.

However, would love to know is there a way from doing in command line in the shell?

Exploring
  • 131
  • Both sed and awk have simple commands to pick a range of lines. `awk 'NR > 50000 { exit } NR >= 45000' does it, and avoids reading the last 350000 records too. – Paul_Pedant Jun 10 '20 at 22:26

1 Answers1

1

Like this:

awk '
    NR>=45000 && NR<=50000
    NR>50000{exit}
' file

You can even pass variables to awk:

awk -v min=45000 -v max=50000 '
    NR >= min && NR <= max
    NR >  max{exit}
' file