Kanrisuru

sed

Stream editor for filtering and transforming text in ruby.
linux manual

Basic Usage

host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
host.echo("Hello world, this is a Cat file.\nCat\nCat\nDog", new_file: '~/text', mode: 'write')

result = host.sed('~/text', 'Cat', 'Dog')
result.success?
true

result.to_s
"Hello world, this is a Dog file.\nDog\nDog\nDog"

Parameters

Field Type Description
path string
Required location of file to perform find and replace on
expression string
Required expression to filter in the file
replacement string
Required replacement to transform in the output stream
in_place boolean
Edits the file in place
regexp_extended boolean
Use extended regular expressions in the script
mode string
Can be either append or write options. Determines how content is saved into a file.
new_file string
The name of the newfile to write the content to

Result

Either returns an array of the substituted file lines, or a nil value if a file is being written to.

Exit Status

Code Description
0 Success
1 Failure

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES