tldr/pages/common/sd.md
Danny Mösch ab00dce9de
sd: Remove option -i in favour of option -p (#4209)
Co-authored-by: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
2020-07-21 22:50:14 +02:00

504 B

sd

Intuitive find & replace CLI.

  • Trim some whitespace using regex:

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

  • Replace words using capture groups:

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

  • Find and replace in a file printing the result to stdout:

sd -p {{'window.fetch'}} {{'fetch'}} {{http.js}}

  • Find and replace across a project changing each file in place:

sd {{'from "react"'}} {{'from "preact"'}} $(find . -type f)