[j-nsp] "replace pattern" Command & White Spaces
Phil Shafer
phil at juniper.net
Mon Aug 1 00:58:08 EDT 2016
Mark Tinka writes:
>I'll work with "sed" in the FreeBSD CLI itself. A little more involved,
>but will get the job done.
You could use an op script, if you want to say completely in the
CLI. See attached.
Thanks,
Phil
--------
version 1.2;
var $conn = jcs:open();
param $pattern;
param $with;
var $pat = "(.*)" _ $pattern _ "(.*)";
main <op-script-results> {
var $rpc = <get-configuration format="text">;
var $res = jcs:execute($conn, $rpc);
var $new := {
for-each (jcs:break-lines($res)) {
var $re = jcs:regex($pat, .);
if ($re) {
expr $re[2] _ $with _ $re[3] _ "\n";
} else {
expr . _ "\n";
}
}
}
var $rpc2 = <load-configuration format="text"> {
<configuration-text> $new;
}
var $res2 = jcs:execute($conn, $rpc2);
copy-of $res2;
}
More information about the juniper-nsp
mailing list