Extract a contiguous range of lines

Extract lines by range pulls a contiguous block of lines out of the input by line number. From and To are one-based and inclusive on both ends, so From = 2, To = 5 keeps lines 2, 3, 4, and 5. To pick by character position instead, use slice text.

Input
Line 1:1 LF cloud_done Saved locally
Result Extract Line Range
0 lines 0 chars

A simple line slicer with one-based, inclusive bounds

From is the first line kept, To is the last line kept. Both are one-based to match the way humans count lines (line 1 is the first line, not line 0). The implementation converts to JavaScript zero-based slicing under the hood: lines.slice(from - 1, to) against the array produced by splitting the input on \r?\n.

If To is past the actual line count the slice stops at the last available line. If From is greater than To the result is empty. Both fields are bounded 1 through 100,000 by the registry, which covers very large pasted blocks without stalling the browser.

Need a non-contiguous selection? Pull each range separately and concatenate, or use regex replace with gm flags to drop unwanted lines. To slice each line by character index inside a larger block, use slice text.

How to use extract a contiguous range of lines

  1. 1Paste your text into the input panel on the left.
  2. 2Set From to the first line number you want to keep (one-based).
  3. 3Set To to the last line number you want to keep (inclusive).
  4. 4Read the extracted block on the right.
  5. 5Click Copy or Download in the output header.

Keyboard shortcuts

Drive TextResult without touching the mouse.

Shortcut Action
Ctrl FOpen the find & replace panel inside the input Plus
Ctrl ZUndo the last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor Plus
EscClose find & replace, or exit fullscreen
Ctrl KOpen the command palette to jump to any tool Plus
Ctrl SSave current workflow draft Plus
Ctrl PRun a saved workflow Plus

What this tool actually does

One-based, inclusive on both ends

From = 1 means the first line. To = 5 keeps line 5. So From = 2, To = 5 returns four lines: 2, 3, 4, 5.

To beyond the file stops at the file

If the input has 10 lines and you set To = 50, the slice stops at line 10. No padding, no error.

From > To returns empty

If you set From later than To the result is the empty string. Useful when the inputs are bound to live form fields.

Both bounds capped at 100,000

The registry sets min: 1 and max: 100000 for both fields. Very large blocks (logs, dumps) work without browser strain.

Output is rejoined with LF

The kept lines are joined with \n regardless of whether the input used CRLF. The trailing newline is dropped because the slice does not include the line terminator after the last kept line.

Worked example

From 2, To 4. Lines 2 through 4 are returned; lines 1, 5, and 6 are dropped.

Input
1: alpha
2: bravo
3: charlie
4: delta
5: echo
6: foxtrot
Output
2: bravo
3: charlie
4: delta

Settings reference

Behaviour Effect on output
From (1-100000) First line kept (one-based, inclusive).
To (1-100000) Last line kept (one-based, inclusive).
To past the file length Slice stops at the last available line.
From > To Returns an empty string.
From = To Returns exactly one line.
Line endings CRLF input becomes LF output (split on \r?\n, join on \n).

FAQ

Are line numbers zero-based or one-based?
One-based. The first line in the input is line 1. From = 1, To = 1 returns the first line.
Is To inclusive?
Yes. The line at To is part of the result. From = 2, To = 5 returns four lines.
What if I ask for lines past the end of the file?
The slice silently stops at the last line. So if the input has 10 lines and you set To = 50, you get lines From through 10.
How do I extract by character position instead of line?
Use slice text. It cuts a substring by start and end character index, with optional per-line mode.
Does anything upload?
No. The transform splits and slices in your browser. Your text never leaves the page.