lbl
Version:
Process stdin, line by line, sort of like AWK but 100% JS
87 lines (65 loc) • 2.04 kB
Markdown
by line, sort of like AWK but 100% JS
- There are a couple of handy globals available
- `$` is an alias for `global`
- `log` is an alias for `console.log`
- `chalk` is available for adding color to ouput
```sh
$ npm install lbl --global
```
```sh
Usage
$ lbl <Options> <STDIN>
Options
-a, --after function to run after processing lines [optional]
-b, --before function to run before processing lines [optional]
-e, --each function to run on each line [required]
-r, --require module file with functions
-h, --help show this usage info
--version show the current version installed
Examples
$ cat ./data/x.file | lbl -r ./scripts/X.js
<<BEGIN>>
> XX
> Matched 1 from 3
$ printf 'x\\nXX\\nxXx' | lbl -e 'x => { n++; if (x.match(/^X/)) { log(chalk.yellow('> ') + x); f++; } }' -b '() => { $.n = 0; $.f = 0; log('<<BEGIN>>'); }' -a '() => { log('> Matched ' + f + ' from ' + n); }'
<<BEGIN>>
> XX
> Matched 1 from 3
```
```js
'use strict';
/* global $, log, chalk, n:true, f:true */
module.exports = {
each: x => {
n++;
if (x.match(/^X/)) {
log(chalk.yellow('> ') + x);
f++;
}
},
before: () => {
$.n = 0;
$.f = 0;
log('<<BEGIN>>');
},
after: () => {
log('> Matched ' + f + ' from ' + n);
}
};
```
ISC © [Buster Collings]()
[ ]: https://badge.fury.io/js/lbl.svg
[ ]: https://npmjs.org/package/lbl
[ ]: https://travis-ci.org/busterc/lbl.svg?branch=master
[ ]: https://travis-ci.org/busterc/lbl
[ ]: https://david-dm.org/busterc/lbl.svg?theme=shields.io
[ ]: https://david-dm.org/busterc/lbl
> Process stdin, line