sed substitution
also: s command, sed s command, text substitution
A sed command that finds text matching a pattern and replaces it with new text. The basic syntax is sed 's/pattern/replacement/' to substitute the first occurrence per line, or sed 's/pattern/replacement/g' to replace all occurrences.
sed substitution is the most common use of the sed (stream editor) command. It scans input line-by-line, matches text against a regular expression pattern, and replaces matching text with a replacement string.
The standard form is s/pattern/replacement/flags. The g flag replaces all matches on each line; without it, only the first match is replaced. Other useful flags include i for case-insensitive matching and 2 to replace only the second occurrence.
Example: sed 's/old/new/g' file.txt replaces every instance of "old" with "new". You can also use different delimiters: sed 's|/path/old|/path/new|g' is clearer when the pattern contains slashes.
sed substitution works on streams (pipes, files, stdin) without loading the entire file into memory, making it efficient for large documents and perfect for command-line text processing pipelines.