sd(1)

πŸ’… sd(1) β€” General Commands Manual, but make it group chat πŸ’…

okay so this is sd(1) from the General Commands Manual, and it's giving find-and-replace main character energy. Bestie, if you've ever wanted to search for a regexp or a literal string and swap it out with something else β€” while looking cute β€” this is your moment. πŸ’…βœ¨


🌸 NAME 🌸

okay so the name is literally sd β€” that's the whole NAME section, bestie. Short, iconic, no notes. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

sd [-p|--preview] [-F|--fixed-strings] [-n|--max-replacements]
[-f|--flags] [-A|--across] [-h|--help] [-V|--version] <FIND>
<REPLACE_WITH> [FILES]

πŸŽ€ DESCRIPTION πŸŽ€

okay so this DESCRIPTION section is literally empty β€” no prose, no deets, just a heading doing abs. πŸ’€ The real tea is in OPTIONS, so scroll with me. 🫢

🌈 OPTIONS 🌈

  • -p, --preview β€” displays changes in a human reviewable format. Heads up: the specifics of that format are likely to change in the future. πŸ‘€
  • -F, --fixed-strings β€” treats FIND and REPLACE_WITH args as literal strings. No regex shenanigans, just exact-string energy. πŸ’…
  • -n, --max-replacements=LIMIT β€” [default: 0] limits the number of replacements that can occur per file. 0 indicates unlimited replacements, so 0 is the no-cap setting, fr fr. πŸ”₯
  • -f, --flags=FLAGS β€” regex flags. May be combined (like -f mc).
    • c β€” case-sensitive
    • e β€” disable multi-line matching
    • i β€” case-insensitive
    • m β€” multi-line matching
    • s β€” make . match newlines
    • w β€” match full words only
  • -A, --across β€” processes each input as a whole rather than line by line. This allows patterns to match across line boundaries but uses more memory and prevents streaming. iconic but not free, bestie. πŸ’€
  • -h, --help β€” print help (see a summary with -h). yes, that's what it says. iykyk. πŸ‘‘
  • -V, --version β€” print version.
  • <FIND> β€” the regexp or string (if using -F) to search for. 🎯
  • <REPLACE_WITH> β€” what to replace each match with. Unless in string mode, you may use captured values like $1, $2, etc. captured-value slay. ✨
  • [FILES] β€” the path to file(s). This is optional β€” sd can also read from STDIN.
Note: sd modifies files in-place by default. See documentation for examples.

πŸ’€ EXIT STATUS πŸ’€

  • 0 β€” successful program execution. slay. βœ…
  • 1 β€” unsuccessful program execution. not the vibe. 😭
  • 101 β€” the program panicked. literally screaming. πŸ’€

πŸ“ EXAMPLES πŸ“

String-literal mode

the -F girlies know: literal strings only, no regex chaos.

$ echo 'lots((([]))) of special chars' | sd -F '((([])))' ''
lots of special chars

Regex use. Let's trim some trailing whitespace

look at that trailing whitespace getting evicted. bye bestie. πŸ‘‹

$ echo 'lorem ipsum 23   ' | sd '\s+$' ''
lorem ipsum 23

Indexed capture groups

capture groups are eating, no cap.

$ echo 'cargo +nightly watch' | sd '(\w+)\s+\+(\w+)\s+(\w+)' 'cmd: $1, channel: $2, subcmd: $3'
cmd: cargo, channel: nightly, subcmd: watch

Find & replace in file

in-place glow-up for http.js. πŸ’–

$ sd 'window.fetch' 'fetch' http.js

Find & replace from STDIN an emit to STDOUT

yes, the original says β€œan emit” β€” we don't fix lore. 🫢

$ sd 'window.fetch' 'fetch' < http.js

okay that's the whole page, bestie β€” source/version: sd 1.0.0, manual: sd(1). The footer didn't give a date, so no fake timestamp energy here. mwah πŸ’‹πŸ«Άβœ¨

πŸ“¦ where this page comes from