Skip to main content
Question Protected by dr_
deleted 24 characters in body
Source Link
Amelio Vazquez-Reina
  • 43.1k
  • 81
  • 211
  • 300

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can get a somewhat similar behaviordo this by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands could pipe to each other many more lines than I am interested in reading (e.g. if I am reading just a few lines in the middle of a huge file)

Is there a way to have the shell just work with and output the lines I want? (while providing only X and Y)?

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can get a somewhat similar behavior by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands could pipe to each other many more lines than I am interested in reading (e.g. if I am reading just a few lines in the middle of a huge file)

Is there a way to have the shell just work with and output the lines I want? (while providing only X and Y)?

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can do this by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands could pipe to each other many more lines than I am interested in reading (e.g. if I am reading just a few lines in the middle of a huge file)

Is there a way to have the shell just work with and output the lines I want? (while providing only X and Y)?

Tweeted twitter.com/#!/StackUnix/status/243861401419014144
added 72 characters in body
Source Link
Amelio Vazquez-Reina
  • 43.1k
  • 81
  • 211
  • 300

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can get a somewhat similar behavior by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands wouldcould pipe to each other many moremany more lines than I am interested in reading (e.g. if I am reading just a few lines in the middle of a huge file)

Is there a way to have the shell just work with and output the lines I want? (while providing only X and Y)?

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can get a somewhat similar behavior by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands would pipe to each other many more lines than I am interested in reading.

Is there a way to have the shell just work and output the lines I want? (while providing only X and Y)?

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can get a somewhat similar behavior by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands could pipe to each other many more lines than I am interested in reading (e.g. if I am reading just a few lines in the middle of a huge file)

Is there a way to have the shell just work with and output the lines I want? (while providing only X and Y)?

Source Link
Amelio Vazquez-Reina
  • 43.1k
  • 81
  • 211
  • 300

cat line X to line Y on a huge file

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).

From what I understand I can get a somewhat similar behavior by piping head into tail or viceversa, i.e.

head -A /path/to/file | tail -B 

or alternatively

tail -C /path/to/file | head -D 

where A,B,C and D can be computed from the number of lines in the file, X and Y.

But there are two problems with this approach:

  1. You have to compute A,B,C and D.
  2. The commands would pipe to each other many more lines than I am interested in reading.

Is there a way to have the shell just work and output the lines I want? (while providing only X and Y)?