Function libaki_gsub::execute

source ·
pub fn execute(sioe: &RunnelIoe, prog_name: &str, args: &[&str]) -> Result<()>
Expand description

execute gsub

params:

  • sioe: stream in/out/err
  • program: program name. etc. “gsub”
  • args: parameter arguments.

return:

  • ok: ()
  • err: anyhow

Examples

Example 1: simple replacements

Leaving one character between ‘a’ and ‘c’, converts ‘a’ and ‘c’ on both sides to ‘*’.

use runnel::RunnelIoeBuilder;

let r = libaki_gsub::execute(&RunnelIoeBuilder::new().build(),
    "gsub", &["-e", "a(.)c", "-f", "*$1*"]);

The $1 mean 1st capture.

Example 2: extracting email address

This extracts the email address and prints the name and address in commas.

use runnel::RunnelIoeBuilder;

let r = libaki_gsub::execute(&RunnelIoeBuilder::new().build(),
    "gsub", &["-e", r"From: ?(.*)<([\w\d_.-]+@[\w\d_-]+\.[\w\d._-]+)>", "-f", "$1, $2"]);

The $1 mean 1st capture. The $2 mean 2nd capture.