mapsd
Because sometimes sed needs an explicit key/value map.
Get Started - Installation - Usage
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
spacesandseparatoryou 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
(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
&
)
<FILES> Files )
The quickstart is quite explicit, but here are some tips & tricks.
-
Beware of spaces in the
.csvfile:old_string1,new_string1is not the same thing asold_string1, new_string1norold_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 oldkeyAND newvaluecannot 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--delimiteror-dflag, for example this could your delimiter if you wanted to--delimiter "===", but if so, your.csvfile 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_string2will be replaced with the stringnew_string2(with a space at the beginning) -
How to delete? simply leaving the new
valuepart empty, like this:old_string1===new_string1 old_string2=== new_string2 old_string3===in this example, all occurences of the string
old_string3will be removed from all matching files. -
My csv has headers: add the
--has-headersflag, andmapsdwill skip the first line of your csv. -
Change files directly without copy: add the
--DANGEROUSLY-REPLACE-INPLACEflag which, as its name suggests... comes with great responsibilities ;)
Installation
# Move it somewhere, like this
Check everything is fine:
Roadmap
- add a
--regexflag to interpret eachkeyin the.csvas a regex instead of a litteral string