0

I have a large text file.

I need to quickly pull a bunch of lines, say from #14600 to #14700, from this file, as a separate file.

How it could be done?

Thomas Dickey
  • 76,765
disfated
  • 138

4 Answers4

7

Using sed

sed -n 14600,14700p filename > newfile

Where:

  • p : Print out the pattern space (to the standard output). This command is usually only used in conjunction with the -n command-line option.

  • n : If auto-print is not disabled, print the pattern space, then, regardless, replace the pattern space with the next line of input. If there is no more input then sed exits without processing any more commands.

serenesat
  • 1,326
3

You can use sed to get those results:

sed -n '14600,14700p;14700q' largefile
Lambert
  • 12,680
  • For me this command worked a bit slower than the one without ;LINEq (when extracting single line 26995107 from a 27169334-line file). Why did you include this q part? – Ruslan Apr 16 '19 at 11:29
1

Old-style:

tail -n +14600 filename | head -n 100

and less-memory-save variant:

head -n 14700 filename | tail -n +14600
Costas
  • 14,916
0

using awk

awk 'NR>=14600&&NR<=147000' filename