text-replace: Simple text replacements from a list of search/replace pairs

[ apache, application, library, program, text ] [ Propose Tags ]

A library and a command-line application for simple string replacements in text files.

The search for strings to replace is performed left-to-right, preferring longer matches to shorter ones.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.1, 0.0.0.2, 0.0.0.3, 0.0.0.4, 0.0.0.6, 0.0.0.8, 0.1, 0.1.0.1, 0.1.0.2, 0.1.0.3
Dependencies base (>=4.10 && <4.17), containers (>=0.5.10.2 && <0.7), optparse-applicative (>=0.14.2 && <0.17), parsec (>=3.1.13 && <3.2), text (>=1.2.2.2 && <1.3), text-replace [details]
License Apache-2.0
Author Chris Martin <ch.martin@gmail.com>
Maintainer Chris Martin <ch.martin@gmail.com>
Category Text, Application
Home page https://github.com/chris-martin/text-replace
Bug tracker https://github.com/chris-martin/text-replace/issues
Source repo head: git clone https://github.com/chris-martin/text-replace
Uploaded by chris_martin at 2022-01-15T04:10:10Z
Distributions
Executables text-replace
Downloads 4149 total (41 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-15 [all 1 reports]

Readme for text-replace-0.1.0.1

[back to package description]

text-replace

Perform simple replacements in a text file, using a list of search/replace pairs.

The search for strings to replace is performed left-to-right, preferring longer matches to shorter ones.

All streams are assumed to be UTF-8 encoded.

Command-line options

Option Description
-h,--help Show help text
-i,--in-file FILEPATH Input file to read (optional, defaults to stdin)
-o,--out-file FILEPATH Output file to write (optional, defaults to stdout)
-m,--mapping MAPPING A list of search/replace pairs, separated by any of the delimiters
-f,--map-file FILEPATH A file containing a list of search/replace pairs, separated by any of the delimiters
-d,--delimiter DELIMITER Add a delimiter that separates search/replace strings in --mapping and in the contents of --map-file
-n,--newline-delimiter Add newline as a delimiter

Examples

text-replace is useful for replacing characters with escape sequences:

$ echo "The (<&&>) operator"        \
    | text-replace --delimiter " "  \
                   --mapping "& &amp; > &gt; < &lt;"
The (&lt;&amp;&amp;&gt;) operator

You can use it to swap strings. In the following example we replace * with ** and vice versa:

$ echo "What *is* going on **here**?"  \
    | text-replace --delimiter " "     \
                   --mapping "* ** ** *"
What **is** going on *here*?

You also have the option to read the input string and replacement list from files, and to write the output to a file:

$ cat input
I am extremely apt to like Haskell once I develop sufficient
aptitude with it.

$ cat replacements
apt -> likely
aptitude -> ability
like -> appreciate

$ text-replace --map-file replacements  \
               --in-file input          \
               --out-file output        \
               --delimiter " -> "       \
               --newline-delimiter

$ cat output
I am extremely likely to appreciate Haskell once I develop
sufficient ability with it.