Skip to content

Commit

Permalink
README++
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Murphy-Skvorzov committed Nov 26, 2015
1 parent 09ad7b8 commit 2f02e52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ Assume a file `dat.jsonl` with lines:

Then:

cat dat.jsonl | jline-clean # Removes all but clean JSON lines
cat dat.jsonl | jline-sort foo.bar # Sorts on the key foo.bar
cat dat.jsonl | jline-filter 'foo.bat>9' # Selects just those lines
cat dat.jsonl | jline-select foo.bar:bar foo.bat:bat mitz # Returns lines such as {"bar":9,"bat":49,"mitz":"ding"}
cat dat.jsonl | jline-pretty # Pretty-prints the JSON
# For a full awk-like tool, write javascript:
cat dat.jsonl | jline-foreach 'console.log(Math.round(record.foo.bar / record.foo.bat))'
cat dat.jsonl | jline-foreach begin::global.sum=0 sum+=record.foo.bar end::'emit(sum)'
cat dat.jsonl | jline-foreach 'begin::global.c=require("crypto")' 'record.hash=c.createHash("sha512").update(record.passwd).digest("hex");emit(record)'
echo '{"url":"http://winning.gold"}' | jline-foreach 'beg::req=require("request-promise")' 'req(record.url).then(console.log)'
... etc
# Import from other formats:
cat data.csv | jline-csv2jl # Convert CSV into lines of JSON dictionaries
cat data.csv | jline-csv2jla # Convert CSV into lines of JSON arrays
echo "SELECT 1,2,3;" | mysql | jline-mysql2jl # Get data from MySQL, one line per record
jline-json2jl -a --path=data.sales dump.json # Extract an array from inside a JSON blob
# Export to other formats:
cat data.jline | jline-csv

# Documentation

Expand All @@ -48,8 +58,8 @@ Use `--help` or refer to the markdown files:
* breakdown [by](./bin/by.md) - Sums fields by a breakdown.

### Power Tools
* [map](./bin/map.md) - Execute arbitrary code for each record and print the updated record.
* [foreach](./bin/foreach.md) - Execute arbitrary code for each record. Awk for JSON lines.
* [map](./bin/map.md) - DEPRECATED as foreach is much more powerful without being more complicated.

### Output
* [pretty](./bin/pretty.md) - Pretty prints the JSON.
Expand Down
4 changes: 3 additions & 1 deletion bin/foreach.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ All standard nodejs functions are available and in addition:

* `tm` - the tree-math library.

### Modules
### Require Modules
You can `require` any npm modules in your NODE_PATH. For example:

# First install a module; it doesn't matter where.
Expand All @@ -68,6 +68,8 @@ You can `require` any npm modules in your NODE_PATH. For example:
# For me the global modules are here:
$ ls /usr/local/lib/node_modules/ | grep request-promise
request-promise
# Yours are probably in:
$ here "$(npm config get prefix)/lib/node_modules"
#
# Now use that module:
#
Expand Down

0 comments on commit 2f02e52

Please sign in to comment.