fsed - Aho-Corasick string replacement utility
Copyright (c) 2015 Will Roberts <firstname.lastname@example.org>
Licensed under the MIT License (see file
Search and replace on file(s), with matching on fixed strings.
fsed is a tool specially designed for situations where you have to
do many string search-and-replace operations with fixed strings
fsed doesn't do regular expressions). By doing all the
searching and replacing on all the patterns at the same time,
can be much faster than tools that do string rewriting one pattern at
a time (like one-liners in
To do its searching,
fsed uses the Aho-Corasick algorithm,
which is a very clever way of matching multiple patterns at the same
time, and was used to implement the original fgrep Unix utility
(now accessed as
grep -F). This algorithm is capable of finding
matches which overlap each other, and in these cases,
choose which matches to rewrite. The policy adopted by
fsed is to
be greedy, and always rewrite the shortest, leftmost match first.
For illustration, imagine a situation where we would like to rewrite
should we do when we see the input string
aaa? Should we produce
bbb in this
pip install fsed
fsed [OPTIONS] PATTERN_FILE [INPUT_FILE [INPUT_FILE2 ...]]
If one or more
INPUT_FILEs are specified,
fsed reads and
concatenates these as its input; otherwise,
fsed reads the
- Set FMT to
sed) to specify the format of
- Specifies that the program output should be written to
OUTFILE. If this option is not used,
fsedwrites to standard output.
fsedmatch only on word boundaries; this flag instructs
\bto the beginning and end of every pattern in
- Sets whether
fsedshould process the input line by line or character by character; the default is
- Indicates that
fsedshould try very hard to always find the longest matches on the input; this is very slow, and forces
--by-lineto be on.
- Quiet operation, do not emit warnings.
- Turns on debugging output.
fsed runs even faster using PyPy:
pypy -m fsed.fsed [OPTIONS] PATTERN_FILE [INPUT_FILE [INPUT_FILE2 ...]]
PATTERN_FILE contains a list of patterns to search and replace in
the input; each pattern is listed on a separate line.
supports two formats for specifying patterns. The default,
specifies strings and their replacements the way the
The character following the
s character is the pattern delimiter,
and can be any character (it does not have to be a forward slash).
The other format,
tsv, specifies patterns using
characters as delimiters:
In this format, there must be only one
<TAB> character per line.
Patterns can contain escape characters:
- Backslash (\)
- ASCII bell (BEL)
- Word boundary
- ASCII formfeed (FF)
- ASCII linefeed (LF)
- Carriage Return (CR)
- Horizontal Tab (TAB)
- ASCII vertical tab (VT)