Skip to main content
Travis CI build status Test code coverage Latest Version

Copyright (c) 2015 Will Roberts <wildwilhelm@gmail.com>

Licensed under the MIT License (see file LICENSE.rst for details).

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 (that is, fsed doesn’t do regular expressions). By doing all the searching and replacing on all the patterns at the same time, fsed can be much faster than tools that do string rewriting one pattern at a time (like one-liners in sed or perl).

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, fsed must 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 a with b, aa with c, and aaa with d. What should we do when we see the input string aaa? Should we produce bbb, bc, cb, or d? fsed produces bbb in this case.

Install

fsed is written in Python; you can install it with pip:

pip install fsed

Usage

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 standard input.

Options:

--pattern-format=FMT

Set FMT to tsv or sed (default is sed) to specify the format of PATTERN_FILE.

-o/--output=OUTFILE

Specifies that the program output should be written to OUTFILE. If this option is not used, fsed writes to standard output.

-w/--words

Makes fsed match only on word boundaries; this flag instructs fsed to append \b to the beginning and end of every pattern in PATTERN_FILE.

--by-line/--across-lines

Sets whether fsed should process the input line by line or character by character; the default is --across-lines.

--slow

Indicates that fsed should try very hard to always find the longest matches on the input; this is very slow, and forces --by-line to be on.

-q

Quiet operation, do not emit warnings.

-v/--verbose

Turns on debugging output.

Note: fsed runs even faster using PyPy:

pypy -m fsed.fsed [OPTIONS] PATTERN_FILE [INPUT_FILE [INPUT_FILE2 ...]]

Pattern File

PATTERN_FILE contains a list of patterns to search and replace in the input; each pattern is listed on a separate line. fsed supports two formats for specifying patterns. The default, sed, specifies strings and their replacements the way the sed utility does:

s/SEARCH/REPLACE/

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 <TAB> characters as delimiters:

SEARCH<TAB>REPLACE

In this format, there must be only one <TAB> character per line.

Patterns can contain escape characters:

\\

Backslash (\)

\a

ASCII bell (BEL)

\b

Word boundary

\f

ASCII formfeed (FF)

\n

ASCII linefeed (LF)

\r

Carriage Return (CR)

\t

Horizontal Tab (TAB)

\v

ASCII vertical tab (VT)

Release files for fsed 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fsed 0.5.3
File Size Uploaded
fsed-0.5.3.tar.gz 503.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fsed 0.5.3
File Interpreter ABI Platform
fsed-0.5.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 522.4 kB

Release files / fsed-0.5.3.tar.gz

Download URL fsed-0.5.3.tar.gz
Size 503.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3e4fd4d5d915b9d7892c038f488a6efe0341ed489c935cec55a314a80f138278
BLAKE2b-256 checksum
How to use checksums
1bbdcea63a3c864b6190df4ae8b3735e5e4ec8595fe7453351fdc6e9f20ddca4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / fsed-0.5.3-py2.py3-none-any.whl

Download URL fsed-0.5.3-py2.py3-none-any.whl
Size 19.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
552ba42897523f3db5d2ccad4970eaef52bbc6a56bb902fd78cf70bea3842af6
BLAKE2b-256 checksum
How to use checksums
a0960c856326c3f80d15fe8b31fb667048514bce79651d3768c7b2d6e664970a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.5.4

2 release files

This release

0.5.3 This release

2 release files

0.5.2

3 release files

0.5.1

3 release files

0.5.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page