Community discussions

MikroTik App
 
mrjohnmohamed
just joined
Topic Author
Posts: 6
Joined: Tue Sep 25, 2012 1:47 pm

how can i delete such a specific line from comment and replace it

Fri May 15, 2015 5:05 pm

how can i delete such a specific line from comment and replace it
without any change for other lines in the comment
plz give suck a script do add comment and delete it
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: how can i delete such a specific line from comment and replace it

Wed May 27, 2015 8:01 pm

We need more information. I assume you're trying to do this to multiple comments, but we need to see them to be able to make a script.
 
mrjohnmohamed
just joined
Topic Author
Posts: 6
Joined: Tue Sep 25, 2012 1:47 pm

Re: how can i delete such a specific line from comment and replace it

Mon Jun 01, 2015 4:03 am

:foreach i in=[/ip hotspot user find ] do={
:local name [/ip hotspot user get $i name]
:local prof [/ip hotspot user get $i profile]
/ip hotspot user set $i comment="rich \r\n man \r\n john"
}}}

you see
comment will come like this
rich
man
john
how can we make script to delete only word man for example
and how can after delete replace it with onther word like women
to be like this
women
man
john
finaly that means
how could we delete such a specific line from comment and replace it with onther?????????
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: how can i delete such a specific line from comment and replace it

Sat Jun 06, 2015 12:51 am

It's possible.... but would take some ugly coding.

Do you have to use \r\n to separate the values? If you used comma separated strings, then this could be done using arrays.

First, all comments would need to be a string like this:
rich,man,john
The main script loops through all comments, extracts values, and changes the ones you specify.
/ip hotspot user
:foreach i in=[find] do={
# get comment, convert to array
  :local in [:toarray [get $i comment]]
  
# change selected array item
  :set ($in->1) "foo"

# output string container  
  :local out
# counter to keep track of where we are at in array
  :local count 1
# loop through array, reconstruct comma separated string
  :foreach j in=$in do={
    :set out ($out . $j)
    :if ($count < [:len $in]) do={
      :set out ($out . ",")
    }
    :set count ($count + 1)
  }
# set comment with new string  
  set $i comment="$out"
}
The line above you want to change is this one. The number 1 is the array position, and the "foo" is the value you want to change to. Every comment will be changed.
:set ($in->1) "foo"
 
mrjohnmohamed
just joined
Topic Author
Posts: 6
Joined: Tue Sep 25, 2012 1:47 pm

Re: how can i delete such a specific line from comment and replace it

Sat Jun 06, 2015 9:58 pm

hello skot
first of all thanks for your help . you are nice one
i tried in mikrotik 5.20 but it didn`t work

look at this pic
and i tried it in a script too
You do not have the required permissions to view the files attached to this post.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: how can i delete such a specific line from comment and replace it

Sat Jun 13, 2015 2:41 am

You are using RouterOS v5, and the script uses an array function that only works in RouterOS v6. You'll have to upgrade to use this script.