Community discussions

MikroTik App
 
tazdevil
newbie
Topic Author
Posts: 29
Joined: Tue Oct 29, 2013 7:12 pm

Delimiter in RouterOS

Fri Dec 20, 2013 3:09 am

Hi,

How do I convert the uptime output from 1d12:28:40 to seconds?

Is there a command in RouterOS for processing delimiters, i.e., "cut -d:" and "awk -F':'" in shell script?

Thanks.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Delimiter in RouterOS

Fri Dec 20, 2013 4:41 pm

maybe :pick could be useful.
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Delimiter in RouterOS

Fri Dec 20, 2013 10:02 pm

maybe :pick could be useful.
I can try to write something if I get a chance later... but the basic idea is use :pick to break it up into its pieces and then convert them to numbers and multiply it all together....
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Delimiter in RouterOS

Fri Dec 20, 2013 10:12 pm

maybe :pick could be useful.
I can try to write something if I get a chance later... but the basic idea is use :pick to break it up into its pieces and then convert them to numbers and multiply it all together....

ros code

:local myString "1d:12:00:00"
        :local days [:pick $myString (0 [:find $myString "d"])]
        :set myString [:pick $myString ([:find $myString "d"]+2) [:len $myString]]
        
        :local hours [:pick $myString (0 [:find $myString ":"])]
        :set myString [:pick $myString ([:find $myString ":"]+1) [:len $myString]]

        :local minutes [:pick $myString (0 [:find $myString ":"])]
        :set myString [:pick $myString ([:find $myString ":"]+1) [:len $myString]]

        :local seconds $myString
Or something like that.
 
tazdevil
newbie
Topic Author
Posts: 29
Joined: Tue Oct 29, 2013 7:12 pm

Re: Delimiter in RouterOS

Sun Dec 22, 2013 5:07 am

Thanks for the example and help.
 
tazdevil
newbie
Topic Author
Posts: 29
Joined: Tue Oct 29, 2013 7:12 pm

Re: Delimiter in RouterOS

Mon Jan 27, 2014 5:01 pm

maybe :pick could be useful.
I can try to write something if I get a chance later... but the basic idea is use :pick to break it up into its pieces and then convert them to numbers and multiply it all together....

ros code

:local myString "1d:12:00:00"
        :local days [:pick $myString (0 [:find $myString "d"])]
        :set myString [:pick $myString ([:find $myString "d"]+2) [:len $myString]]
        
        :local hours [:pick $myString (0 [:find $myString ":"])]
        :set myString [:pick $myString ([:find $myString ":"]+1) [:len $myString]]

        :local minutes [:pick $myString (0 [:find $myString ":"])]
        :set myString [:pick $myString ([:find $myString ":"]+1) [:len $myString]]

        :local seconds $myString
Or something like that.
If "myString" was "1d:12:00:00", it above script worked great. However, if "myString" was "12:34:56", the variable "days" would return 1 as well. I am using RouterOS v6.7.
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Delimiter in RouterOS

Mon Jan 27, 2014 5:42 pm

You'll have to insert an if statement then to account due the variability.

Sent from my SCH-I545 using Tapatalk
 
tazdevil
newbie
Topic Author
Posts: 29
Joined: Tue Oct 29, 2013 7:12 pm

Re: Delimiter in RouterOS

Tue Jan 28, 2014 7:40 am

You'll have to insert an if statement then to account due the variability.

Sent from my SCH-I545 using Tapatalk
Thanks efaden!