Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active December 16, 2015 03:19
Show Gist options
  • Save joyrexus/5368680 to your computer and use it in GitHub Desktop.
Save joyrexus/5368680 to your computer and use it in GitHub Desktop.
Sample unix-style filter that reads from STDIN sans args.
#!/usr/bin/env coffee
fs = require 'fs'
transform = (data) ->
result = data.toString().replace /h/g, 'm'
process.stdout.write result
if process.argv.length > 2
transform fs.readFileSync(file, 'utf8') for file in process.argv[2..]
else
process.stdin.on 'data', transform
process.stdin.resume()

filter.coffee

A sample coffee filter.

$ echo "hi world" | filter.coffee
mi world
$ cat hello.txt
hello world! 

$ filter.coffee hello.text
mello world!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment