deexp
v0.1.1
Published
A simple command-line utiilty for modifying text files based off regular expressions.
Downloads
4
Maintainers
Readme
deExp
A simple Node command-line utility for file-alteration with the usage of Regular Expressions.
Installation
Install with npm:
npm install deexp
Usage
The command takes in four arguments. Run via npx:
npx deexp [fromfile] [tofile] [mode] [...args]
Where:
- fromfile - the path to the text file to be used as input
- tofile - the path of the text file to be used as output (created if doesn't exist, otherwise truncated)
- mode - a command to be run on the file, one of:
- re/replace
- ad/add
- de/delete
- args - the appropriate arguments for the command in question
For examples of usage/output, see the 'tests' directory.
Commands available (and arguments for them)
re/replace
Will replace the given regular expression with a string.
Arguments:
- Regular expression for search and replacement
- New string to replace with
ad/add
Will add the new string to the file in the given regular expressions range.
Arguments:
- String to add
- Regular expression to add occurrence of after (optional, if 3. is present)
- Regular expression to add occurrence of before (optional, if 2. is present)
Note: either of 2. or 3. MUST be given
de/delete
Will delete (cut out) all the occurrences of the regular expression passed from the file.
Arguments:
- Regular expression for deletion
Using in scripts
The package is particularly useful when writing scripts for textual transformations of files, for every single operation of transfromation is but a single command. They can get very complex, without having to employ a larger transformation vocabulary, than add/delete/replace. Similarly, the transformations can be carried out on a single file, making the program perfect for the said format.