Modern and opinionated find/replace CLI program. Short version of Find and Substitute, read as /fɔ.dɐ.s(ɨ)/ :).
- Find and replace text (and RegEx) from stdin
- Inline replace in files[1]
- Modern PCRE RegEx, same as you use on
rgand your favourite programming languages - Use RegEx groups as replacement
- Case-insensitive matching
- String-literal mode - no RegEx and escaping characters when you don't need RegEx
- Find files and directories using glob double-start patterns
- Replace with interactive mode, similar to
git patchand vim replace/c - Ignore files and directories with glob double-star patterns
[1] When provided a file, it creates a temporary file, writes the content and replaces the original file, following symlinks by default.
There is no package for Linux or MacOS yet, so:
- Download the most recent version for your platform
- Extract the tarball
- Move the binary to a directory in the
PATH - Voilà
wget https://github.com/gabrieloliverio/fds/releases/latest/download/fds-linux-amd64.tar.gz
tar zxvf fds-linux-amd64.tar.gz
mv fds /usr/local/binwget https://github.com/gabrieloliverio/fds/releases/latest/download/fds-darwin-arm64.tar.gz
tar zxvf fds-darwin-arm64.tar.gz
mv fds /usr/local/binecho subject | fds [ options ] search_pattern replace
fds [ options ] search_pattern replace ./file
fds [ options ] search_pattern replace ~/directory
fds [ options ] search_pattern replace ~/directory/**/somepattern*
Options:
-l, --literal Treat pattern as a regular string instead of as Regular Expression
-i, --insensitive Ignore case on search
-c, --confirm Confirm each substitution
-v, --verbose Print debug information
--ignore-globs Ignore glob patterns, comma-separated. Ex. --ignore-globs "vendor/**,node_modules/lib/**.js"
--workers Number of workers created to process the substitutions. Default value: 4
Examples:
# From stdin
echo "baz bar" | fds baz foo # Prints out "foo bar"
# Replace in a file
fds foo bar ./file.txt
# Replace in files present in a directory
fds foo bar ./dir
# Replace in files present in a directory using 8 workers instead of the default 4
fds foo bar ./dir --workers 8
# Confirm each replacement. See *Interactive replace*
fds -c foo bar ./file.txt
# Literal mode
fds -l "->" "=>" ./file.txt
# Insensitive mode
fds -i foo bar ./file.txt
# Replace recursively in .txt files
fds foo bar ./dir/**/*.txtAsks for confirmation on each occurrence.
Example:
$ fds dolor foo ./lorem/file.txt -c
File ./lorem/file.txt
2 Sed do eiusmod tempor incididunt ut labore et _dolor_fooe magna aliqua.
[y]es [n]o [a]ll q[uit]: y[y]es replaces only this occurrence [n]o does not replace it [a] replaces all occurrences in the file and other files (when supplied a directory) [q] quits, leaving the file unmodified
- Stdin (pipe) + replacement as string
- Positional parameters
- Replacement as RegEx
- "Inline" replace for single file, writing content into temp file and renaming it
- Support for symlinks (similar to sed's
--follow-symlink) - Support for string-literal mode
- Support for case-insensitive mode
- Interactive mode
- Include line numbers
- Directories
- Glob
- Accept --ignore-globs
- Concurrency when reading/writing several files
- Backup file
- Ignore binary files
- Ignore files listed in .gitignore
- Multiple files, directories and/or globs
