sed
Files
SKILL.mdagentsreferencesscripts
Install
Install only this skill with npx skills
npx skills add alisonaquinas/llm-shared-skills --skill 'sed' -g -y
Install the containing skill bundle
/plugin install shared-skills@llm-skills
This skill is bundled inside shared-skills. Use
npx skills when you only want this skill, or install the bundle once to make every included skill available through the plugin marketplace flow. Browse the full skill bundle repository at github.com/alisonaquinas/llm-shared-skills.Invoke
Invoke this skill after installation
/shared-skills:sed
SKILL.md
name: sed description: Transform text streams with sed for line filtering, global substitutions, and in-place file edits. Use when the agent needs to search-and-replace with regex, filter specific line ranges, delete patterns, or apply repeatable text transformations.
sed
Stream editor for deterministic, line-oriented text transformation and filtering.
Quick Start
- Verify
sedis available:sed --versionorman sed - Establish the command surface:
man sedorsed --help - Start with a read-only probe:
sed 's/old/new/' file.txt
Intent Router
Load only the reference file needed for the active request.
references/install-and-setup.md— Installing sed (GNU, BSD) on macOS, Linux, Windowsreferences/cheatsheet.md— Common flags, substitution, line selection, deletion, extended regexreferences/advanced-usage.md— Multi-line patterns, address ranges, branching, hold space, GNU vs BSD differencesreferences/troubleshooting.md— Regex escaping, in-place edit failures, performance, encoding issues
Core Workflow
- Verify sed variant (GNU vs BSD):
sed --versionorman sed - Test on sample data first (never on production):
sed 's/old/new/' sample.txt - Use
-n(quiet) with explicitpcommands to prevent double-printing - Use
-i.bak(with backup suffix) for in-place edits to allow rollback - Quote scripts carefully to avoid shell interpretation
Quick Command Reference
sed --version # Check version (GNU vs BSD)
sed 's/old/new/' file.txt # Replace first match per line
sed 's/old/new/g' file.txt # Replace all matches per line
sed -n '10,20p' file.txt # Print lines 10-20 only
sed -n '/pattern/p' file.txt # Print lines matching pattern
sed '/pattern/d' file.txt # Delete lines matching pattern
sed -i.bak 's/old/new/g' file.txt # In-place edit with backup
sed -e 's/a/b/' -e 's/c/d/' file.txt # Multiple scripts
sed 'N;s/\n/ /' file.txt # Join consecutive lines
man sed # Full manual and options
Safety Notes
| Area | Guardrail |
|---|---|
| Regex escaping | Special characters (/, , &, $) in patterns/replacements require careful escaping. Use -E for extended regex. Test on sample data. |
| In-place edits | Always use -i.bak (with backup suffix), never -i alone. Allows easy rollback if command is incorrect. |
| Double-printing | With -n flag, only requested lines print. Without -n, all lines print by default (may duplicate matches). |
| GNU vs BSD | Flag syntax differs (-i.bak vs -i.bak spacing, -E vs -r for extended regex). Test cross-platform or specify variant. |
| Performance | Complex multi-line patterns using hold space can be slow on large files. Use line-oriented tools (grep, awk) when possible. |
| Encoding | sed may corrupt multi-byte UTF-8 if patterns split characters. Test with actual data; consider iconv preprocessing. |
Source Policy
- Treat the installed
sedbehavior andman sedas runtime truth. - Use GNU sed documentation (gnu.org/software/sed) for GNU-specific extensions.
- Use BSD sed manual for BSD variant behavior differences.
Resource Index
scripts/install.sh— Install sed (GNU sed or BSD sed) on macOS or Linux.scripts/install.ps1— Install sed on Windows or any platform via PowerShell.