SUPER-SED(1)

πŸ’– NAME πŸ’–

ssed β€” ok bestie, it's the super sed stream editor, version 3.61 ✨ Like regular sed but extra. We love her.


πŸ¦‹ SYNOPSIS πŸ¦‹

sed [OPTION]... {script-only-if-no-other-script} [input-file]...

🌸 DESCRIPTION 🌸

So sed is a stream editor. And a stream editor does basic text transformations on an input stream β€” that stream being either a file, or input coming at you from a pipeline 🫢

And like, yeah, in some ways she's similar to an editor that lets you script your edits (think ed), but here's the thing: sed makes only one pass over the input(s), which is lowkey why she's so much more efficient. But honestly? It's her ability to filter text inside a pipeline that really sets her apart from every other type of editor. main character energy, fr fr πŸ‘‘


✨ OPTIONS ✨

  • -n, --quiet, --silent β€” suppresses the automatic printing of the pattern space. (Shhh 🀫 she just won't print unless you tell her to.)
  • -e script, --expression=script β€” adds script to the commands that are gonna be executed.
  • -f script-file, --file=script-file β€” adds the contents of script-file to the commands that are gonna be executed.
  • -i[SUFFIX], --in-place[=SUFFIX] β€” edits files in place (and makes a backup if you supply an extension πŸ’Ύ).
  • -l N, --line-length=N β€” specifies the desired line-wrap length for the l command.
  • --posix β€” disables all GNU extensions. No cap.
  • -r, --regexp-extended β€” use extended regular expressions in the script.
  • -R, --regexp-perl β€” use Perl 5's regular expressions syntax in the script. πŸͺ
  • -s, --separate β€” treats files as separate, rather than as one single continuous long stream.
  • -u, --unbuffered β€” loads minimal amounts of data from the input files and flushes the output buffers more often.
  • --help β€” displays this help and exits.
  • --version β€” outputs version info and exits.

So here's the tea: if you don't give her a -e, --expression, -f, or --file option, then the first non-option argument gets taken as the sed script to interpret. And every remaining argument after that? Those are the names of the input files πŸ—‚οΈ If you specify no input files at all, then standard input is read. Periodt.

πŸ“§ E-mail bug reports to: bonzini@gnu.org . Bestie, be sure to include the word `ssed` somewhere in the `Subject:` field, okay?? πŸ™ˆ

She's based on GNU sed version 4.1. πŸ’…


πŸŽ€ COMMAND SYNOPSIS πŸŽ€

This is just a lil brief synopsis of sed commands β€” a reminder for the girlies who already know sed 😌 For fuller descriptions you must consult other documentation (like the texinfo document). Iykyk.

🌈 Zero-address `commands` 🌈

  • : label β€” label for b and t commands.
  • #comment β€” the comment extends until the next newline (or the end of a -e script fragment).
  • } β€” the closing bracket of a { } block.

πŸ“ Zero- or One- address commands πŸ“

  • = β€” print the current line number.
  • a \ followed by text β€” append text, which has each embedded newline preceded by a backslash.
  • i \ followed by text β€” insert text, which has each embedded newline preceded by a backslash.
  • q β€” immediately quit the sed script without processing any more input, except that if auto-print is not disabled the current pattern space will be printed.
  • Q β€” immediately quit the sed script without processing any more input.
  • r filename β€” append text read from filename.
  • R filename β€” append a line read from filename.

🧚 Commands which accept address ranges 🧚

  • { β€” begin a block of commands (end with a }).
  • b label β€” branch to label; if label is omitted, branch to end of script.
  • t label β€” if a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script.
  • T label β€” if no s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script.
  • c \ followed by text β€” replace the selected lines with text, which has each embedded newline preceded by a backslash.
  • d β€” delete pattern space. Start next cycle.
  • D β€” delete up to the first embedded newline in the pattern space. Start next cycle, but skip reading from the input if there is still data in the pattern space.
  • h H β€” copy/append pattern space to hold space.
  • g G β€” copy/append hold space to pattern space.
  • x β€” exchange the contents of the hold and pattern spaces.
  • l β€” list out the current line in a `visually unambiguous` form.
  • n N β€” read/append the next line of input into the pattern space.
  • p β€” print the current pattern space.
  • P β€” print up to the first embedded newline of the current pattern space.
  • s/regexp/replacement/ β€” attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp. πŸ”₯
  • w filename β€” write the current pattern space to filename.
  • W filename β€” write the first line of the current pattern space to filename.
  • y/source/dest/ β€” transliterate the characters in the pattern space which appear in source to the corresponding character in dest.

πŸ’œ Addresses πŸ’œ

Sed commands can be given with no addresses, in which case the command will be executed for all input lines. With one address, in which case the command will only be executed for input lines which match that address. Or with two addresses, in which case the command will be executed for all input lines which match the inclusive range of lines starting from the first address and continuing to the second address. 🫢

Three things to note about address ranges, bestie, write these down:

  • the syntax is addr1,addr2 (i.e., the addresses are separated by a comma);
  • the line which addr1 matched will always be accepted, even if addr2 selects an earlier line;
  • and if addr2 is a regexp, it will not be tested against the line that addr1 matched.

After the address (or address-range), and before the command, a ! may be inserted, which specifies that the command shall only be executed if the address (or address-range) does not match.

The following address types are supported:

  • number β€” match only the specified line number.
  • first~step β€” match every step'th line starting with line first. For example, `sed -n 1~2p` will print all the odd-numbered lines in the input stream, and the address 2~5 will match every fifth line, starting with the second. (This is an extension.)
  • $ β€” match the last line.
  • /regexp/ β€” match lines matching the regular expression regexp.
  • \cregexpc β€” match lines matching the regular expression regexp. The c may be any character.

GNU sed also supports some special 2-address forms πŸ‘‘:

  • 0,addr2 β€” start out in "matched first address" state, until addr2 is found. This is similar to 1,addr2, except that if addr2 matches the very first line of input the 0,addr2 form will be at the end of its range, whereas the 1,addr2 form will still be at the beginning of its range.
  • addr1,+N β€” will match addr1 and the N lines following addr1.
  • addr1,~N β€” will match addr1 and the lines following addr1 until the next line whose input line number is a multiple of N.

⭐ REGULAR EXPRESSIONS ⭐

POSIX.2 BREs should be supported, but they aren't completely, because of performance problems 😭 The \n sequence in a regular expression matches the newline character, and similarly for \a, \t, and other sequences.


πŸ’€ BUGS πŸ’€

E-mail bug reports to bonzini@gnu.org. Be sure to include the word `sed` somewhere in the `Subject:` field. Also, please include the output of `sed --version` in the body of your report if at all possible πŸ™ (girl, it genuinely helps)


Copyright Β© 2003 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, to the extent permitted by law. 🫣 Like, none. Zero. Nada.


πŸŽ€ SEE ALSO πŸŽ€

awk(1), ed(1), grep(1), tr(1), perlre(1), sed.info, any of various books on sed, the sed FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.html), http://sed.sf.net/grabbag/. πŸ“š

The full documentation for super-sed is maintained as a Texinfo manual. If the info and super-sed programs are properly installed at your site, the command

info sed

should give you access to the complete manual. ✨


And that's the whole page, bestie!! πŸ¦‹ This was super-sed version 3.61, dated February 2005, and it lives in section 1 β€” SUPER-SED(1) πŸ’… Go forth and stream-edit, you absolute icon. πŸ‘‘πŸ’–

πŸ“¦ where this page comes from