Text · 52 tools · nothing uploads

Extract lines

Extract lines. Runs entirely on your device, nothing is uploaded.

Input

Options

live

Extract lines keeps only the lines of a pasted text that match a substring or regex, fall inside a numbered range, or both. invert flips the selection to keep everything that does not match. A pattern and a range can combine, but giving neither is refused outright. Ranges are 1-based and inclusive of both ends.

Questions

Can I combine a pattern and a line range?

Yes. Give both and a line has to satisfy the range first, then the pattern test is applied on top of what the range selected; giving neither is refused with "extract-lines needs a pattern, a range, or both".

How does invert behave with only a range and no pattern?

It flips the range selection itself, keeping every line outside the given range instead of inside it, since there is no pattern test to invert in that case.

What format does the range need to be in?

Exactly "start-end", both whole numbers, 1-based and inclusive, such as "3-10". Anything else is refused with a message quoting what you gave and what format is expected.

Can the pattern be a regular expression?

Yes, if useRegex is turned on; otherwise pattern is matched as a plain substring anywhere in the line. An invalid regex is refused with the JavaScript engine's own error message included.

Are matched line numbers preserved in the output?

No. The output is only the matching lines themselves, in their original order, with no line-number prefix; combine it with Number lines afterward if you need the original positions.

Compare

ToolRuns on the CLILive as you type
Extract linesYesYes
Number linesYesYes
Reverse linesYesYes
Shuffle linesYesYes
Sort lines by lengthYesYes
Unique lines with countsYesYes
Prefix or suffix linesYesYes

Related Text tools