"git@gitlab.caltech.edu:cs1-24fa/minimathematica.git" did not exist on "373c84a886defe468d7539adf7cc0bee0f79b3ca"
Commit 4b308279 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

npm run grep alias

parent 76def09a
No related merge requests found
Showing with 4 additions and 4 deletions
+4 -4
......@@ -52,7 +52,7 @@ For example, `some-command | grep ERROR` will print out only the lines of output
Implement `grep` (including 4 of its command-line flags) in Node.js.
Your `grep` will be invoked using `node grep.js [-i] [-r] [-v] [-z] pattern [files ...]`.
Your `grep` will be invoked using `npm run grep [-i] [-r] [-v] [-z] pattern [files ...]`.
The flags `-i`, `-r`, `-v`, and `-z` are described later.
A simple implementation of `grep` would read the entire input, loop over its lines, and print the lines that match the pattern.
......@@ -75,15 +75,15 @@ The values should be interpreted as follows:
If no filenames are given and `-r` is not used, the standard input (`process.stdin`) should be searched instead.
- `recursive` stores whether the flag `-r` was used.
If so, `files` are expected to be directories and are searched recursively.
For example, `node grep.js pattern -r dir1 dir2` searches all files in `dir1` and `dir2` (and all their subdirectories) for `pattern`.
For example, `npm run grep pattern -r dir1 dir2` searches all files in `dir1` and `dir2` (and all their subdirectories) for `pattern`.
If no directories are provided, the current directory (`.`) should be searched instead.
You can use the provided function `readdirRecursive()` to search each directory.
- `gunzip` stores whether the flag `-z` was used.
If so, all files are treated as [gzip](https://en.wikipedia.org/wiki/Gzip)ped text files and are unzipped before being searched.
For example, if `independence.txt` is compressed to `independence.txt.gz`, then `node grep.js -z ss independence.txt.gz` prints the same lines as `node grep.js ss independence.txt`.
For example, if `independence.txt` is compressed to `independence.txt.gz`, then `npm run grep -z ss independence.txt.gz` prints the same lines as `npm run grep ss independence.txt`.
Note that `-z` and `-r` can be used together.
- `ignoreCase` stores whether the flag `-i` was used.
If so, the pattern is case-insensitive, e.g. `node grep.js -i error` would match a line containing `error`, `ERROR`, or `ErRoR`.
If so, the pattern is case-insensitive, e.g. `npm run grep -i error` would match a line containing `error`, `ERROR`, or `ErRoR`.
You can use `RegExp(pattern, 'i')` to make a case-insensitive regular expression.
- `invert` stores whether the flag `-v` was used.
If so, the pattern specifies lines to *exclude*; only the lines that don't match the pattern are printed.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment