Crates.io | mapsd |
lib.rs | mapsd |
version | 0.0.1 |
source | src |
created_at | 2024-10-04 23:09:30.895753 |
updated_at | 2024-10-04 23:09:30.895753 |
description | Find & Replace text in multiple files using an explicit CSV of Before/After pairs. |
homepage | https://github.com/Jonarod/mapsd |
repository | https://github.com/Jonarod/mapsd |
max_upload_size | |
id | 1397220 |
size | 56,825 |
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
)
.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
.html
files in the ./Documents
directorymapsd "./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.)
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 as old_string1, new_string1
nor old_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 old key
AND new value
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 string new_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, and mapsd
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 ;)
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
cargo install mapsd
--regex
flag to interpret each key
in the .csv
as a regex instead of a litteral string