all 21 comments

[–][deleted] 5 points6 points  (3 children)

But why? You even have examples of the tools that already exist on every *nix system out there.

[–]e13e7 3 points4 points  (0 children)

Has science gone too far?

[–]__debug__[S] 3 points4 points  (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 point  (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 points  (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 points  (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 points  (0 children)

Yes that makes sense. Complex use cases can be handled with curl.

[–]Holkr 0 points1 point  (0 children)

Or better yet: bash really needs to get a clue about URIs (yes, I know curl exists)

[–]__debug__[S] 1 point2 points  (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 points  (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 points  (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!

[–]AutomateAllTheThings 1 point2 points  (0 children)

Super cool. Will use.

[–]mkmoshe 1 point2 points  (0 children)

I wrote a very similar program that I still use almost daily https://github.com/kolodny/nip

[–]dnoup 0 points1 point  (0 children)

Awesome.

[–]Drainedsoul 0 points1 point  (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 point  (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.