from Hacker News

Show HN: A more ergonomic sed using JavaScript regexes

by ariabuckles on 8/12/19, 6:33 PM with 0 comments

I love `sed`, but specifying in-place replacement across linux/mac is challenging, and I find both the regular expression options hard to remember the exact syntax for.

So I built a small wrapper around String.prototype.replace to give the syntax and power of javascript regular expressions (and, optionally, javascript functions):

https://github.com/ariabuckles/jsed

Or to install:

    npm install -g @ariabuckles/jsed
Some examples:

You can use it pretty similarly to `sed`:

    echo "this is a test" | jsed '\w+' 'word:$&'
    > word:this word:is word:a word:test
Or you can use it more like javascript when needed:

     echo "1 2 3 4" | jsed '/\d+/g' '(num) => num%2 == 0 ? "even" : "odd"'