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
Change log changelog.md
Dependencies base (>=4.14 && <4.18), containers (>=0.6.4 && <0.7), optparse-applicative (>=0.16.1 && <0.18), parsec (>=3.1.14 && <3.2), text (>=1.2.4 && <1.3 || >=2.0 && <2.1), text-replace [details]
License Apache-2.0
Author Chris Martin
Maintainer Chris Martin
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 2023-01-02T04:26:31Z
Distributions NixOS:0.1.0.3
Executables text-replace
Downloads 3703 total (50 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for text-replace-0.1.0.3

[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

  • -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.