mirror of
https://github.com/nymurbd/MikroTik-scripts.git
synced 2025-07-10 18:14:29 +02:00
global-functions: implement $Grep...
... that returns the first line that matches a pattern.
This commit is contained in:
parent
072d349473
commit
b834517baa
1 changed files with 21 additions and 0 deletions
|
@ -30,6 +30,7 @@
|
||||||
:global GetRandom20CharAlNum;
|
:global GetRandom20CharAlNum;
|
||||||
:global GetRandom20CharHex;
|
:global GetRandom20CharHex;
|
||||||
:global GetRandomNumber;
|
:global GetRandomNumber;
|
||||||
|
:global Grep;
|
||||||
:global HexToNum;
|
:global HexToNum;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global IsDefaultRouteReachable;
|
:global IsDefaultRouteReachable;
|
||||||
|
@ -367,6 +368,26 @@
|
||||||
:return [ :rndnum from=0 to=[ $EitherOr [ :tonum $1 ] 4294967295 ] ];
|
:return [ :rndnum from=0 to=[ $EitherOr [ :tonum $1 ] 4294967295 ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# return first line that matches a pattern
|
||||||
|
:set Grep do={
|
||||||
|
:local Input ([ :tostr $1 ] . "\n");
|
||||||
|
:local Pattern [ :tostr $2 ];
|
||||||
|
|
||||||
|
:if ([ :typeof [ :find $Input $Pattern ] ] = "nil") do={
|
||||||
|
:return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
:do {
|
||||||
|
:local Line [ :pick $Input 0 [ :find $Input "\n" ] ];
|
||||||
|
:if ([ :typeof [ :find $Line $Pattern ] ] = "num") do={
|
||||||
|
:return $Line;
|
||||||
|
}
|
||||||
|
:set Input [ :pick $Input ([ :find $Input "\n" ] + 1) [ :len $Input ] ];
|
||||||
|
} while=([ :len $Input ] > 0);
|
||||||
|
|
||||||
|
:return [];
|
||||||
|
}
|
||||||
|
|
||||||
# convert from hex (string) to num
|
# convert from hex (string) to num
|
||||||
:set HexToNum do={
|
:set HexToNum do={
|
||||||
:local Input [ :tostr $1 ];
|
:local Input [ :tostr $1 ];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue