diff --git a/README.md b/README.md index 3faa542..dd811e3 100644 --- a/README.md +++ b/README.md @@ -393,6 +393,15 @@ sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js'); Reads an input string from `files` and performs a JavaScript `replace()` on the input using the given search regex and replacement string or function. Returns the new string after replacement. +Note: + +Like unix `sed`, ShellJS `sed` supports capture groups. Capture groups are specified +using the `$n` syntax: + +```javascript +sed(/(\w+)\s(\w+)/, '$2, $1', 'file.txt'); +``` + ### sort([options,] file [, file ...]) ### sort([options,] file_array) diff --git a/src/sed.js b/src/sed.js index 590ba74..dfdc0a7 100644 --- a/src/sed.js +++ b/src/sed.js @@ -25,6 +25,15 @@ common.register('sed', _sed, { //@ //@ Reads an input string from `files` and performs a JavaScript `replace()` on the input //@ using the given search regex and replacement string or function. Returns the new string after replacement. +//@ +//@ Note: +//@ +//@ Like unix `sed`, ShellJS `sed` supports capture groups. Capture groups are specified +//@ using the `$n` syntax: +//@ +//@ ```javascript +//@ sed(/(\w+)\s(\w+)/, '$2, $1', 'file.txt'); +//@ ``` function _sed(options, regex, replacement, files) { // Check if this is coming from a pipe var pipe = common.readFromPipe();