NAME
sd
SYNOPSIS
sd [-p|--preview] [-F|--fixed-strings] [-n|--max-replacements] [-f|--flags] [-h|--help] [-V|--version] <FIND> <REPLACE_WITH> [FILES]
DESCRIPTION
OPTIONS
-p, --preview
Display changes in a human reviewable format (the specifics of the format are likely to change in the future)
-F, --fixed-strings
Treat FIND and REPLACE_WITH args as literal strings
-n, --max-replacements=LIMIT [default: 0]
Limit the number of replacements that can occur per file. 0 indicates unlimited replacements
-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
-h, --help
Print help (see a summary with '-h')
-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
[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. |
|||
1 |
Unsuccessful program execution. |
|||
101 |
The program panicked. |
EXAMPLES
String-literal mode
$ echo 'lots((([]))) of
special chars' | sd -s '((([])))'
lots of special chars
Regex use. Let's trim some trailing whitespace
$ echo 'lorem ipsum 23 ' |
sd '\s+$' ''
lorem ipsum 23
Indexed capture groups
$ echo 'cargo +nightly
watch' | sd '(\w+)\s+\+(\w+)\s+(\w+)' 'cmd: $1, channel: $2,
subcmd: $3'
123 dollars and 45 cents
Find & replace in file
$ sd 'window.fetch' 'fetch' http.js
Find & replace from STDIN an emit to STDOUT
$ sd 'window.fetch' 'fetch' < http.js