Stream editor command for manipulating text one line at a time. Sed is similar to the
many Unix implementations, but only supports the "s" command (substitute) currently.
Pass or pipe the text to process or a filename along with the --file flag.
.
{code:bash}
sed "hello world" s/hello/goodbye/
Outputs: "goodbye world"
{code}
.
The substitute command syntax is "s/replaceMe/withMe/" where "s" is the command,
"replaceMe" is a CFML regular expression, and "withMe" is a replacement expression.
.
Supported pattern flags are "g" (global) which replaces all instances per line, and
"i" (ignore case) which makes the replacement case-insensitive.
.
{code:bash}
echo "one hundred and one" | sed s/ONE/two/gi
Outputs: "two hundred and two"
{code}
.
All other regex rules follow what is implemented in REReplace() CFML function.
.
The delimiter in the subsdtitute command does not have to be "/". Whatever character
that immediatley follows the "s" will be used. This can be useful where the regex
and/or replacement text contain a "/".
.
This example uses a tilde (~) as the delimiter. It reads a file, replaces all instances
of a given file path, and writes the file back out.
.
{code:bash}
sed --file config.cfm s~/var/www/~/sites/wwwroot/~i > config.cfm
{code}