Skip to content

sed2

Stream editor for filtering and transforming text.

Synopsis

tofu sed2 <from> <to> [files...] [flags]

Description

A sed-like stream editor with modern, readable syntax. Replace occurrences of a pattern with a replacement string.

Flags

Flag Short Description Default
--search-type -t Pattern type: literal, regex regex
--in-place -i Edit files in place false
--ignore-case -I Case-insensitive search false
--global -g Replace all occurrences on each line false

Examples

Replace first occurrence on each line:

tofu sed2 "old" "new" file.txt

Replace all occurrences (global):

tofu sed2 -g "old" "new" file.txt

Case-insensitive replacement:

tofu sed2 -I "error" "warning" log.txt

Edit file in place:

tofu sed2 -i "foo" "bar" config.txt

Use literal string (not regex):

tofu sed2 -t literal "user.name" "user.email" file.txt

Regex with capture groups:

tofu sed2 "(\w+)@example.com" "$1@newdomain.com" emails.txt

Read from stdin:

echo "hello world" | tofu sed2 "world" "universe"

Process multiple files:

tofu sed2 -g "TODO" "DONE" *.md