{"_id":"1cli","_rev":"4-c16505ed4203637964984e2a02fea2ce","name":"1cli","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"1cli","version":"0.0.1","description":"Use JS code snippets for command-line file munging","keywords":[],"main":"src/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"bin":{"1cli":"1cli.js"},"repository":{"type":"git","url":"git+https://github.com/umrigar/1cli.git"},"author":"","license":"ISC","bugs":{"url":"https://github.com/umrigar/1cli.js/issues"},"homepage":"https://github.com/umrigar/1cli.js#readme","dependencies":{"commander":"^7.0.0","csv":"^5.3.2"},"gitHead":"b35e406cd80d55790ad9731b4878f5ac93c4a36a","_id":"1cli@0.0.1","_nodeVersion":"15.8.0","_npmVersion":"7.5.1","dist":{"integrity":"sha512-OkIoXk/tJLEEPh+NgMW9mkjFY32bzjtOyG3i+hQytZ3z67hlKxaTrDOJNUyO+D8p/H0hakOtR4RIV0dYvBFCyg==","shasum":"d9aa57316e7f7290c7b686cb0110740fdfbc9707","tarball":"https://registry.npmjs.org/1cli/-/1cli-0.0.1.tgz","fileCount":14,"unpackedSize":27454,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgKNasCRA9TVsSAnZWagAAcFwP/jCdHB+RUWqaGGB11p4v\nXD4nBTAvU05/QtJqmtsyCig5xrqAvWKlPoCdgxY/S0gONihQ+/Equp2DB6q4\noYvxlqpFkgx02z9M60KkCbdnu6Y5X0ecisk3Sr4sGqAZ21aTc15/q/FobIVz\nyzkl/LDkuEZTfUNayjvNWRmVX2k1fAiIGwyTG0V1ivqyAO5ayFmT/s5CZGDG\nu/oXDzo7/0vFQTI1JhFmqdBw9wM2WRflPxPiTwbVCzB6AQWZIblanzQUG7IT\nvlauNM9IhZxxNPUWS3xpIcvxDRQMiqFvmttEfSRmUXTfuaZ8zylW9OOTQ+7J\ns0/WN/0KT7tzYQHVl5qa8hO4XKT5ilo0xL3Y00N/vQVmDqZWIHSx+oRzD0u8\nyOGIYtCQETxmyrmsBPGCfmQ27u2JvHBKgo4q+EhVGae/Hy/SgCu0GIUPnjd6\n3Nov9wlVyMARoBiRO46h60yH4wuIMa8+VVFgtpsyxkm/mEk+5UcZBNZK7I4u\nXTFYkkv+KOcN6fkfUKM8WvUBRoYcMoh/ujhvKgO4G+l+a1zGHxp4moAOXpsC\n08qQiSVluC45A0Kabd5qkbMTEVk8CbrG+Zm3ToPqXfW6FzxSjE9WnWpmOENk\njWvVW0jWZ75bZl9HKZrMmddj9UvSCyvUPMfQaNYF3HitzL1rc2/NerI8z1wz\nqULe\r\n=rJTc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFjmgrYqL2KRfiLGjm4Eh78yEsXPnBeTaBHOnQNgEgrPAiEA1nPmelt2hrMP9mtqUJXcQIw9MS3tQaP9VXMtX2ZUgZA="}]},"_npmUser":{"name":"umrigar","email":"lamarts@gmail.com"},"directories":{},"maintainers":[{"name":"umrigar","email":"lamarts@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/1cli_0.0.1_1613289132290_0.7618478388389103"},"_hasShrinkwrap":false},"0.0.2":{"name":"1cli","version":"0.0.2","description":"Use JS code snippets for command-line file munging","keywords":["command-line","1line","cli","shell","one-line"],"main":"src/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"bin":{"1cli":"1cli.js"},"repository":{"type":"git","url":"git+https://github.com/umrigar/1cli.git"},"author":"","license":"ISC","bugs":{"url":"https://github.com/umrigar/1cli/issues"},"homepage":"https://github.com/umrigar/1cli","dependencies":{"commander":"^7.0.0","csv":"^5.3.2"},"gitHead":"b35e406cd80d55790ad9731b4878f5ac93c4a36a","_id":"1cli@0.0.2","_nodeVersion":"15.8.0","_npmVersion":"7.5.1","dist":{"integrity":"sha512-fSem3K6XO+Gunvs1hHh7BW4r9ImxtHQsG6Rhy2vAjGv2ykb4DtaLuUoeyqLky/15UP9YBWVo1ri5mNBEgvFfhg==","shasum":"cb515abd8de8cad1c388b061a8082089f08fbaed","tarball":"https://registry.npmjs.org/1cli/-/1cli-0.0.2.tgz","fileCount":14,"unpackedSize":27423,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgKNsgCRA9TVsSAnZWagAA18QP/jIDc3XynSMmsN0hK6Gq\nnahzEkfAF8EsXE/Kfe1tNop0ytX5IGc4uwHB8reNF4iI1pWw6/8iNeMzhjNg\nFXmJSnY/U7wTNQ9vldWvgmtMweg59ju+ErDNFYfeGMHom5uJtAsE1e72VLYN\nSHVlCRVaz+MfezAt3pOmD8J7e2XKqZfU93F9bSFMZScMdSP2JYiKKErnd3fW\nCAuIsYQ6bjrjmwtlqpBXn88+sIlauOzWWeSo2wvXcVo7u2V287UQ6Z5nlXC3\negJkxnbGnNWLKfx/aaJpZUz2gjWEf3a2mLUYDaQaGDHE2iVamTH+gBTEtnxI\nGXplTz03CJKOqQZpL+b7UsrMq4rHzrYgpNa1lDjXCvqrPFrMcBsM7Jw+FtsK\n8/Sev2q4ven2SQTpf8Q1/73LusU/2OBSe4d9L1HbYwpf/P3ZgFXJ2m2WsiY3\n+691IeZRKFOyQ6Oyr5tvZmgnRcF93r7uo0/bqcYNwchXsUvlCewweu996Vi6\n0YqUKkVHJFeCAZJkddnvFS8UpRLIIJH+/DXttCtsbyHtysmX+jxKDVRbhUWu\nwEh++NlN9D7UKVRiatXqZB1EEsX14VLHE+sazB7SLdwoiNmEW/reey9sX7BP\nXqqVyrSgbwAtOS/YOGI73HCvUm6lH746+/L8ArbPOjegRAHLz1nYEdlP3qwu\nwUoQ\r\n=Wc43\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFgn87ZDCw+316HruhkNOaRTwfSd3VmLXjnXVO00XAM+AiBH/SXHguWJyiqY1DRpBMof3jUlo8GwU8KkrSGAibYjhw=="}]},"_npmUser":{"name":"umrigar","email":"lamarts@gmail.com"},"directories":{},"maintainers":[{"name":"umrigar","email":"lamarts@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/1cli_0.0.2_1613290272237_0.3194501971497088"},"_hasShrinkwrap":false}},"time":{"created":"2021-02-14T07:41:26.441Z","1.0.0":"2021-02-14T07:41:26.564Z","modified":"2022-04-04T10:12:54.075Z","0.0.1":"2021-02-14T07:52:12.458Z","0.0.2":"2021-02-14T08:11:12.378Z"},"maintainers":[{"name":"umrigar","email":"lamarts@gmail.com"}],"description":"Use JS code snippets for command-line file munging","homepage":"https://github.com/umrigar/1cli","keywords":["command-line","1line","cli","shell","one-line"],"repository":{"type":"git","url":"git+https://github.com/umrigar/1cli.git"},"bugs":{"url":"https://github.com/umrigar/1cli/issues"},"license":"ISC","readme":"# 1cli\n\nUse JavaScript code snippets within \"one-line\" shell command-lines for\nfile munging.\n\n  + Special support for json, [jsonl](https://jsonlines.org/),\n    comma-separated csv files, tab-separated csv files and pipe |\n    separated csv files.\n\n  + Short names for useful functionality:\n\n      + `_` represents the current \"line\".\n\n      + `_p(...)` like `console.log(...)`.\n\n      + `_j(o)` convert `o` to/from json.\n\nFor example, to convert a .csv file to a .jsonl file:\n\n```shell\n# show contents of csv file:\n$ cat examples/vm-ips.csv \nuser,course,ip\njohn,cs123,192.168.1.2\nbill,cs223,192.168.1.3\nmary,cs123,10.1.2.3\nsue,cs223,192.168.1.4\n# convert\n$ $ 1cli -e '_p(_j(_))'  examples/vm-ips.csv > ~/tmp/vm-ips.jsonl\n# show result\n$ cat ~/tmp/vm-ips.jsonl \n{\"user\":\"john\",\"course\":\"cs123\",\"ip\":\"192.168.1.2\"}\n{\"user\":\"bill\",\"course\":\"cs223\",\"ip\":\"192.168.1.3\"}\n{\"user\":\"mary\",\"course\":\"cs123\",\"ip\":\"10.1.2.3\"}\n{\"user\":\"sue\",\"course\":\"cs223\",\"ip\":\"192.168.1.4\"}\n$\n```\n\nThe `.csv` extension on the input file results in it being\nread into a list of object.  The `-e` `--eval` option will run\nprovided code block `_p(_j(_))`, printing out each csv object\nas json.\n\nThe following example shows converting the same file `vm-ips.csv`\ninto a json file with keys for each user:\n\n```shell\n$ 1cli -e 'BEGIN o={}' -e 'o[_.user]=_' -e 'END _p(_j(o))' \\\n     examples/vm-ips.csv >~/tmp/vm-ips.json\n#show output (edited for limiting line length)\n$ cat ~/tmp/vm-ips.json\n{\"john\":{\"user\":\"john\",\"course\":\"cs123\",\"ip\":\"192.168.1.2\"},\n \"bill\":{\"user\":\"bill\",\"course\":\"cs223\",\"ip\":\"192.168.1.3\"},\n  \"mary\":{\"user\":\"mary\",\"course\":\"cs123\",\"ip\":\"10.1.2.3\"},\n  \"sue\":{\"user\":\"sue\",\"course\":\"cs223\",\"ip\":\"192.168.1.4\"}\n}\n$\n```\n\nThe `BEGIN` code block is executed only once at the start\nof the script and is used to set up an empty object `o`.\nThe subsequent code block adds each csv object to the `o` object\nunder its `user` key.\n\nThe following example filters `vm-ips.csv` to produce\na jsonl contains all csv objects have `ip`'s starting with `10`.\n\n```shell\n$ 1cli -e '_.ip.startsWith('10.') && _p(_j(_))' examples/vm-ips.csv \n{\"user\":\"mary\",\"course\":\"cs123\",\"ip\":\"10.1.2.3\"}\n$\n```\n\nThe following example uses the previously generated `vm-ips.json`\nfile along with a new `student-info.jsonl` file to join\nentries for the same id's.  Note that we match the `user` field\nto the portion before the `@` of the email from the `student-info.jsonl`\nfile:\n\n```shell\n# show student-infos.jsonl input file\n$ cat examples/student-info.jsonl \n{ \"id\": \"123-465-mar\", \"first\": \"Mary\", \"last\": \"Traub\", \"email\": \"mary@x.com\" }\n{ \"id\": \"132-456-sue\", \"first\": \"Sue\", \"last\": \"Rawls\", \"email\": \"sue@x.com\" }\n{ \"id\": \"123-456-jhn\", \"first\": \"John\", \"last\": \"Smith\", \"email\": \"john@x.com\" }\n{ \"id\": \"123-456-bil\", \"first\": \"Bill\", \"last\": \"Gray\", \"email\": \"bill@x.com\" }\n# join user from vm-ips.json to email id from student-infos.json\n$ 1cli -e 'u=_.email.m(/^[^@]+/)[0]; x={..._contents[0][u], ..._}; _p(_j(x))' \\\n    ~/tmp/vm-ips.json examples/student-info.jsonl \\\n    > ~/tmp/student-vm-ips.jsonl\n# show results (edited for line-length)\n$ cat ~/tmp/student-vm-ips.jsonl \n{\"user\":\"mary\",\"course\":\"cs123\",\"ip\":\"10.1.2.3\",\"id\":\"123-465-mar\",\n    \"first\":\"Mary\",\"last\":\"Traub\",\"email\":\"mary@x.com\"}\n{\"user\":\"sue\",\"course\":\"cs223\",\"ip\":\"192.168.1.4\",\"id\":\"132-456-sue\",\n    \"first\":\"Sue\",\"last\":\"Rawls\",\"email\":\"sue@x.com\"}\n{\"user\":\"john\",\"course\":\"cs123\",\"ip\":\"192.168.1.2\",\"id\":\"123-456-jhn\",\n    \"first\":\"John\",\"last\":\"Smith\",\"email\":\"john@x.com\"}\n{\"user\":\"bill\",\"course\":\"cs223\",\"ip\":\"192.168.1.3\",\"id\":\"123-456-bil\",\n    \"first\":\"Bill\",\"last\":\"Gray\",\"email\":\"bill@x.com\"}\n$\n```\n\nHere is the manual produced using the `--man` option:\n\n```text\n$ 1cli --man\nUsage: 1cli [options] [...path]\n\nOptions:\n  -d, --debug                  output generated functions on stderr\n  -e, --eval <code>            evaluate <code>. Can be specified multiple\n                               times. If --loop, then evaluate for each _\n                               \"line\". If <code> starts with BEGIN/END then\n                               evaluate only at start/end.  (default: [])\n  -f, --field-sep <sep>        use <sep> to split _ line into _0, _1, ... when\n                               --loop (default: \"/\\\\s+/\")\n  -h, --help                   display help for command\n  -l, --no-loop                run code only once\n  -L, --loop                   repeat code for each _ \"line\" (default: true)\n  -m, --no-monkey              do not monkey-patch standard classes\n  -M, --monkey                 monkey-patch standard classes (default: true)\n  --man                        output manual on stdout\n  -p, --no-print               do not print _ \"line\" after each loop iteration\n  -P, --print                  print _ \"line\" after each loop iteration\n                               (default: false)\n  --src <path>                 like specifying <path> in [...path]; always\n                               recognize --ext extensions and loop over \"lines\"\n                               when applicable\n  --src-l <path>               alias for --src-no-loop\n  --src-lx <path>              alias for --src-no-ext-no-split\n  --src-no-ext <path>          like specifying <path> in [...path]; loop over\n                               \"lines\" but do not recognize special -X\n                               extensions\n  --src-no-loop <path>         like specifying <path> in [...path]; recognize\n                               --ext extensions but do not loop over \"lines\"\n  --src-no-loop-no-ext <path>  like specifying <path> in [...path] arguments;\n                               do not recognize special extensions; do not loop\n                               over \"lines\"\n  --src-x <path>               alias for --src-no-ext\n  -v, --version                output the version number\n  -x, --no-ext                 no special handling for extensions in [path...]\n  -X, --ext                    special handling for json, jsonl, csv, psv, tsv\n                               extensions in [path...] (default: true)\n\nProcess files specified by [...path] or by --src* options\nusing --eval <code> blocks. \n\nIf a path is specified as '-', then read from standard input; if an\nextension is required, then attempt to guess an extension based on the\ninitial content.\n\nIf --loop, then repeat <code> blocks for each \"line\" of file contents.\nA <code> block starting with 'BEGIN' is executed only once at the\nstart. A <code> block starting with 'END' is executed only once at the\nend.\n\nUnless extension processing has been turned off by specifying\n--no-ext or by using the --src-*no-ext options, the following\nspecial extensions are recognized:\n\n  .csv:       parsed as comma-separated CSV with first line as header\n  .json:      parsed as JSON content; never split into lines.\n  .jsonl:     each line parsed as JSON; always split into lines\n  .psv:       parsed as pipe '|' separated CSV with first line as header\n  .tsv:       parsed as tab-separated CSV with first line as header\n\n\nNote that all of the above extensions except .json are read\nin as an array of objects and processed within the --eval\nloop blocks (unless --no-loop or --src-no-loop* is specified).\n\nThe code for each block has access to the following constants:\n\n  _contents:  array of contents of all files specified by <path...> or --src\n  _d:         _d(path): return array of contents of directory dir\n  _entries:   _entries(obj) => Object.entries(obj)\n  _f:         _f(path): returns array of \"lines\" from path\n  _j:         _j(arg) => convert arg to/from JSON\n  _keys:      _keys(obj) => Object.keys(obj)\n  _p:         _p(...) is an alias for console.log(...)\n  _paths:     array of paths of all files specified by <path...> or --src\n  _values:    _values(obj) => Object.values(obj)\n  _x:         _x(cmd) returns stdout for executing shell command cmd\n\n\nWhen a block is being executed repeatedly because\nof the --loop option, it has access to the following additional\nvariables:\n\n  _:          current \"line\" being processed\n  _c:         contents of current path\n  _n:         current line number (1-origin)\n  _path:      current path being processed\n\n\nSpecifying --monkey-patch, patches standard classes with\nconvenience methods:\n\n  m:          str.m(...) => str.match(...); results[0, 1]...] put into $0, $1...\n  r:          str.r(...) => str.replace(...)\n  s:          str.s(...) => str.split(...)\n\n\n$ \n```\n","readmeFilename":"README.md"}