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
)?
Asked by Amelio Vazquez-Reina
(42851 rep)
Sep 6, 2012, 10:38 PM
Last activity: Aug 6, 2023, 09:33 AM
Last activity: Aug 6, 2023, 09:33 AM