sed
1974fragletshellscriptingstream-processing.sed
docker run --rm --platform="linux/amd64" 100hellos/sed:latest
MCP + fragletc
MCPstdin
This language supports code execution via MCP and the fragletc CLI. Stdin piping is supported.
Install fragletc →sed is a shell scripting and stream-processing language first appearing in 1974.
Hello World
#!/bin/sed -f
# BEGIN_FRAGLET
1s/^/Hello World!/
# END_FRAGLETCoding Guide
Language Version
GNU sed (stream editor)
Execution Model
- Stream editor that processes text line by line
- Reads from stdin or files
- Applies commands to each line (or specified lines)
- Outputs modified text to stdout
Key Characteristics
- Line-oriented processing
- Commands operate on pattern space (current line)
- Addresses specify which lines to process (line numbers, regex patterns)
- Commands:
s(substitute),p(print),d(delete),a(append),i(insert), etc. - Flags:
g(global),p(print),i(case-insensitive) - Delimiters:
/is standard, but any character can be used - Case-sensitive pattern matching (unless using
iflag)
Fragment Authoring
Write valid sed commands. Your fragment becomes the script body. Your fragment will execute as part of the sed script.
Important: sed processes input line by line. If your fragment needs to process multiple lines, you may need to use the hold space or multi-line commands.
Available Commands
Standard sed commands are available:
s/pattern/replacement/flags- Substitute pattern with replacementp- Print the pattern spaced- Delete the pattern spacea\text- Append text after the current linei\text- Insert text before the current linec\text- Change/replace the current liney/src/dst/- Transliterate charactersq- Quit processing=- Print line numberr file- Read file and append to outputw file- Write pattern space to file
Common Patterns
- Substitute:
s/old/new/ors/old/new/g(global) - Print:
p(usually with-nflag to suppress default output) - Delete:
d - Append:
a\Text to append - Insert:
i\Text to insert - Address ranges:
1,5s/old/new/(lines 1-5),/pattern/s/old/new/(matching lines) - Multiple commands:
s/old/new/; s/foo/bar/or-e 's/old/new/' -e 's/foo/bar/' - Conditional:
/pattern/{ s/old/new/; p; }
Examples
# Simple output
1s/^/Hello from fragment!/
# Multiple substitutions
1s/^/Hello /; 1s/$/ World!/
# Print with line numbers
=; p
# Append text
a\This is appended text
# Insert text
i\This is inserted text
# Substitute with case-insensitive flag
s/hello/HELLO/gi
# Process specific lines
1,3s/old/new/g
# Pattern-based substitution
/pattern/s/old/new/
# Multiple commands on same line
1s/^/Prefix /; 1s/$/ Suffix/
# Delete and substitute
1d; 2s/old/new/
# Conditional processing
/error/{ s/error/ERROR/; p; }
# Creative formatting: Transform a list into a formatted output
1s/^/Colors: /; 2s/^/ * /; 3s/^/ * /; 3s/$/ (favorite)/Caveats
- sed processes one line at a time by default
- Pattern space contains the current line
- Hold space can store data between lines (advanced)
- Addresses are line numbers or regex patterns
- Commands are separated by
;or newlines - Use
-nflag withpcommand to avoid duplicate output - Delimiters can be any character:
s|old|new|works the same ass/old/new/ - Special characters in patterns need escaping:
\.,\*,\+, etc. - Replacement text can reference matched groups:
s/\(.*\)/\1/ - Multi-line operations require special handling (hold space,
Ncommand)
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=sed
1s/^/Args: /Stdin Upper
#!/usr/bin/env -S fragletc --vein=sed
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/Test
#!/usr/bin/env -S fragletc --vein=sed
1s/^/Hello World!/Connections
influences