1 unstable release
0.0.1 | Oct 4, 2024 |
---|
#13 in #text-replacement
187 downloads per month
18KB
133 lines
Quickstart
1. Download latest release for your system
Or you can also build it from source using cargo
(see Installation). Then move the binary somewhere like in /usr/local/bin
(just make sure it is some folder already in your $PATH
)
2. Create a .csv
file with 2 columns:
old_string1,new_string1
old_string2,new_string2
old_string3,new_string3
WARNING: beware of the
spaces
andseparator
you put here !! Every character counts, even spaces
3. Replace all occurrences of the 1st column with the 2nd, over all .html
files in the ./Documents
directory
mapsd "./Documents/**/*.html" -m ./my_map.csv
(No worries, by default it applies the replacement in a copy of the files. When you feel you are ready you can add the --DANGEROUSLY-REPLACE-INPLACE
flag to actually replace things in place.)
Usage
mapsd 0.0.1
Find & Replace text in multiple files using an explicit CSV of Before/After pairs.
USAGE:
mapsd [FLAGS] [OPTIONS] <FILES>
FLAGS:
--has-headers CSV has headers
-h, --help Prints help information
--DANGEROUSLY-REPLACE-INPLACE Replace files in-place (USE WITH CAUTION)
--silent Suppress output
-V, --version Prints version information
OPTIONS:
-d, --delimiter <delimiter> CSV delimiter [default: ,]
-m, --map <map> Path to the CSV file containing key/value pairs [default: map.csv]
-p, --prefix <prefix> Prefix to use for the resulting copied file [default: replaced.]
ARGS:
<FILES> Files to process (glob pattern)
The quickstart is quite explicit, but here are some tips & tricks.
-
Beware of spaces in the
.csv
file:old_string1,new_string1
is not the same thing asold_string1, new_string1
norold_string1,new_string1
. All characters count and WILL be matched/replaced as-is. -
Pick the right delimiter: the default delimiter is
,
but of course that means both your oldkey
AND newvalue
cannot contain the same character,
. In some cases this cannot work, so you will need to get creative and maybe invent some new delimiters to be more explicit and avoid conflicts. In such case, just provide it with the--delimiter
or-d
flag, for example this could your delimiter if you wanted to--delimiter "==="
, but if so, your.csv
file should look like this:old_string1===new_string1 old_string2=== new_string2 old_string3===new_string3
(NOTE: in the above example, all occurences of the string
old_string2
will be replaced with the stringnew_string2
(with a space at the beginning) -
How to delete? simply leaving the new
value
part empty, like this:old_string1===new_string1 old_string2=== new_string2 old_string3===
in this example, all occurences of the string
old_string3
will be removed from all matching files. -
My csv has headers: add the
--has-headers
flag, andmapsd
will skip the first line of your csv. -
Change files directly without copy: add the
--DANGEROUSLY-REPLACE-INPLACE
flag which, as its name suggests... comes with great responsibilities ;)
Installation
Download pre-compiled binaries
Go to the [releases](https://github.com/Jonarod/mapsd/releases), and download the lastest binary for your platform.Build from source
[Install rust](https://www.rust-lang.org/tools/install), then:git clone git@github.com:Jonarod/mapsd.git
cd mapsd
cargo build --release
# Move it somewhere, like this
sudo mv ./target/release/mapsd /usr/local/bin/
Check everything is fine:
mapsd --version
Install using `cargo`
Make sure you have [Rust installed](https://www.rust-lang.org/tools/install), then:cargo install mapsd
Roadmap
- add a
--regex
flag to interpret eachkey
in the.csv
as a regex instead of a litteral string
Dependencies
~5.5MB
~101K SLoC