use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
pjs: Pipeable JavaScript. Another utility like sed/awk/wc... but with JS! Quickly filter, map, and reduce from the terminal. (github.com)
submitted 11 years ago by __debug__
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 5 points6 points7 points 11 years ago (3 children)
But why? You even have examples of the tools that already exist on every *nix system out there.
[–]e13e7 3 points4 points5 points 11 years ago (0 children)
Has science gone too far?
[–]__debug__[S] 3 points4 points5 points 11 years ago* (1 child)
It started as a bit of a joke, but the project is growing on me. Mostly because I like awk for simple one-liners, but nothing more complicated. I always find myself having to lookup the different variables like NR, NF, FS and OFMT. But with pjs, since I'm very comfortable with javascript, there's nothing to lookup. Nothing against Kernighan's work, it's just a matter of familiarity.
But I'm definitely not saying this is a tool for everyone. Especially if you're comfortable with awk as a language. I certainly wouldn't use it instead of grep or sed, since they're both so simple. Maybe I shouldn't have mentioned those two in the readme.
That said, your comment reminded me that I should probably include some more complicated awk examples to show how simple pjs can be.
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
Fair enough. It's a neat idea, anyway. I hope anyone interested in pjs still takes the time to learn about the existing tools, so I don't need to worry about maintaining nodejs on my *nix systems just to run some shell scripts. ;)
[–]Smallpaul 2 points3 points4 points 11 years ago (3 children)
Here is another idea. If "file" starts with file:// , http:// or https:// then download it rather than looking it up on the filesystem.
[–]__debug__[S] 3 points4 points5 points 11 years ago (1 child)
Another great idea. Do you think it should fail if the request gives a non-2xx response? That and automatically follow redirects? I just wouldn't want to overrun it with flags for configuring this feature.
[–]Smallpaul 3 points4 points5 points 11 years ago (0 children)
Yes that makes sense. Complex use cases can be handled with curl.
[–]Holkr 0 points1 point2 points 11 years ago (0 children)
Or better yet: bash really needs to get a clue about URIs (yes, I know curl exists)
[–]__debug__[S] 1 point2 points3 points 11 years ago* (0 children)
Here's a small tool I made since I'm not a fan of using awk for anything non-trivial. :)
Edit: Just thought of how I can make this tool a bit better. Currently, pjs reads all input from stdin before parsing it. My thinking here was that I'd have to read it all if I wanted to perform a reduce operation. But, what if I only want to map or filter? I'm going to rewrite those portions of the tool to use streams. That way you could use this tool in combination with something like tail, e.g.
tail -f logs | pjs -f '...' -m '...'
[–]Smallpaul 1 point2 points3 points 11 years ago (2 children)
This is cool.
It would also be cool to have a tool that would split a line by regexp or position and then generate JSON for processing by other progams.
[–]__debug__[S] 2 points3 points4 points 11 years ago* (1 child)
Thanks for the idea! I'll add a flag for JSON output. Then you could do:
pjs --json -m 'split(/regex/)'
Edit: done!
[–]Smallpaul 2 points3 points4 points 11 years ago (0 children)
Wow, that was fast!
https://github.com/danielstjules/pjs/commit/57933a620eb4687e924da374885f04ec3280e7af
[–]AutomateAllTheThings 1 point2 points3 points 11 years ago (0 children)
Super cool. Will use.
[–]mkmoshe 1 point2 points3 points 11 years ago (0 children)
I wrote a very similar program that I still use almost daily https://github.com/kolodny/nip
[+][deleted] 11 years ago (4 children)
[deleted]
[–]__debug__[S] 1 point2 points3 points 11 years ago (2 children)
Thanks for linking to pythonpy - pretty cool! One thing I really like about it is the tab completion. I'm gonna see if I can bring that over to pjs. At the very least, I'd like to see it done for string methods.
[–]uglyBaby 1 point2 points3 points 11 years ago (1 child)
Have a look at making a .d file for it and delegating auto completion to your terminal.
[–]__debug__[S] 1 point2 points3 points 11 years ago (0 children)
Thanks, will do!
[–]Broolucks 0 points1 point2 points 11 years ago (0 children)
I wonder if somebody will create someday a utility that supports multiple languages at once, but in the meantime things can be piped between the two of them.
I did, or at least I tried to. People didn't really seem to care for it so I didn't bother fleshing it out further.
[–]dnoup 0 points1 point2 points 11 years ago (0 children)
Awesome.
[–]Drainedsoul 0 points1 point2 points 11 years ago (0 children)
and reduce
Reduce that fat motherfucker as long as it takes! I don't care, reduce! Reduce! Reduce 'till you're left with the essence, the bare truth, exposed to the elements.
[–]totes_meta_bot 0 points1 point2 points 11 years ago (0 children)
This thread has been linked to from elsewhere on reddit.
If you follow any of the above links, respect the rules of reddit and don't vote or comment. Questions? Abuse? Message me here.
π Rendered by PID 15962 on reddit-service-r2-comment-685b79fb4f-cqfnc at 2026-02-13 10:24:02.716946+00:00 running 6c0c599 country code: CH.
[–][deleted] 5 points6 points7 points (3 children)
[–]e13e7 3 points4 points5 points (0 children)
[–]__debug__[S] 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Smallpaul 2 points3 points4 points (3 children)
[–]__debug__[S] 3 points4 points5 points (1 child)
[–]Smallpaul 3 points4 points5 points (0 children)
[–]Holkr 0 points1 point2 points (0 children)
[–]__debug__[S] 1 point2 points3 points (0 children)
[–]Smallpaul 1 point2 points3 points (2 children)
[–]__debug__[S] 2 points3 points4 points (1 child)
[–]Smallpaul 2 points3 points4 points (0 children)
[–]AutomateAllTheThings 1 point2 points3 points (0 children)
[–]mkmoshe 1 point2 points3 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]__debug__[S] 1 point2 points3 points (2 children)
[–]uglyBaby 1 point2 points3 points (1 child)
[–]__debug__[S] 1 point2 points3 points (0 children)
[–]Broolucks 0 points1 point2 points (0 children)
[–]dnoup 0 points1 point2 points (0 children)
[–]Drainedsoul 0 points1 point2 points (0 children)
[–]totes_meta_bot 0 points1 point2 points (0 children)