# Stream Editor

Apply safe sed-style scripts to pasted text: substitute, delete, print, insert, append, change, branch, and address by line or regex.

## Run it

- **CLI:** `gizza tool stream-editor "foo

keep this line
drop this line"`
- **Web:** https://gizza.ai/tools/stream-editor/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/stream-editor/tool.json

## Inputs

- `text` — Input text _(field)_
- `script` — Command script _(field)_
- `quiet` — Quiet mode (sed -n) _(field)_
- `ignore_case` — Ignore case in regexes _(field)_
- `whole_buffer` — Treat input as one whole buffer _(field)_
- `regex_flavor` — Regex flavor _(field)_
- `line_ending` — Output line ending _(field)_
- `max_output_lines` — Max output lines _(field)_

## Output

- Edited text (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `text` — Input text
- `script` — Command script
- `quiet` — Quiet mode (sed -n)
- `ignore_case` — Ignore case in regexes
- `whole_buffer` — Treat input as one whole buffer
- `regex_flavor` — Regex flavor
- `line_ending` — Output line ending
- `max_output_lines` — Max output lines

Example: `https://gizza.ai/tools/stream-editor/?text=foo%0A%0Akeep%20this%20line%0Adrop%20this%20line&script=s%2Ffoo%2Fbar%2Fg%0A%2Fdrop%2Fd&quiet=true&ignore_case=true&whole_buffer=true&regex_flavor=basic&line_ending=lf&max_output_lines=100000`

---

## Run sed-style edits without a shell

Stream Editor applies a small sed/ed-style command script to pasted text entirely in the browser. It uses sed's familiar cycle model: each input line becomes the pattern space, matching commands run in order, and the line is printed automatically unless **Quiet mode** is enabled.

Common scripts work as expected:

- `s/foo/bar/g` — substitute every `foo` with `bar` on each line.
- `/^$/d` — delete blank lines.
- `2,5d` — delete lines 2 through 5.
- `/error/p` with **Quiet mode** — print only matching lines.
- `1i header`, `$a footer`, and `/old/c replacement` — insert, append, or change text.

Filesystem and shell sed commands are deliberately unavailable in the sandbox. Commands such as reading a file, writing a file, or executing a shell command return a clear error instead of reaching outside the pasted text.

### Worked example

Input:

```text
foo

keep foo
drop this
```

Script:

```sed
s/foo/bar/g
/drop/d
/^[[:space:]]*$/d
```

Output:

```text
bar
keep bar
```

The first command replaces `foo`, the second deletes any line containing `drop`, and the third removes blank lines.

### Limits and edge cases

- Output is capped by **Max output lines** (default 100,000) to stop accidental explosions.
- A separate step cap stops runaway branch loops.
- **Basic** regex mode follows sed/BRE-style escaping. Choose **Extended** for `sed -E` style groups and alternation.
- **Whole buffer** mode loads the whole input into one pattern space for multi-line edits; most line-by-line scripts should leave it off.
- CRLF output is available for Windows-oriented text, but input line endings are normalized before editing.

## FAQ

<details>
<summary>Is this a full GNU sed clone?</summary>

No. It implements the common stream-editing core for pasted text: addresses, ranges, substitutions, delete, print, insert/append/change, transliteration, hold space, labels and branches. Commands that require a filesystem or shell are blocked because this tool runs in a sandboxed browser/runtime model.

</details>

<details>
<summary>When should I turn on Quiet mode?</summary>

Use Quiet mode for `sed -n` style extraction. With quiet off, every line that survives the script is printed automatically. With quiet on, output appears only when the script uses commands such as `p`, `P`, `=`, or `l`.

</details>

<details>
<summary>What is the difference between basic and extended regex?</summary>

Basic mode matches traditional sed regular expressions where grouping and alternation are escaped, such as `\(foo\|bar\)`. Extended mode matches `sed -E` style patterns like `(foo|bar)` and `ID-([0-9]+)`.

</details>

<details>
<summary>Can it edit files directly?</summary>

No. Paste text in and copy or download the result. Direct file reads/writes and shell execution are intentionally unavailable so the script cannot access anything outside the text you supplied.

</details>

## Related tools

- [Text Pipeline Playground](https://gizza.ai/tools/text-pipeline-playground/): Pipe pasted text through a chain of transforms — grep, reject, regex replace, sort, unique, head/tail, split, join — with a tiny safe DSL. Free, private, in your browser.
- [Find and Replace Text](https://gizza.ai/tools/find-replace/): Find and replace text with literal or regex matching, case-sensitive or not, all matches or just the first. Runs in your browser, nothing is uploaded, free.
- [Extract Action Items from Meeting Notes](https://gizza.ai/tools/action-item-extractor/): Extract action items, owners, and decisions from meeting notes or daily notes with deterministic rules. Markdown checklist or JSON, private in-browser.
- [Add Line Numbers](https://gizza.ai/tools/add-line-numbers/): Add line numbers to every line of text online, like nl or cat -n — custom start, step, separator, and alignment. Free and private, runs in your browser.
- [ANSI Log Renderer](https://gizza.ai/tools/ansi-log-renderer/): Paste ANSI-colored terminal output or CI logs and render them as HTML, or strip escape codes to plain text. Handles 16-color, 256-color, and truecolor SGR codes.
