Page 1 of 1

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

Posted: Fri May 15, 2015 5:05 pm
by mrjohnmohamed
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

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

Posted: Wed May 27, 2015 8:01 pm
by skot
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.

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

Posted: Mon Jun 01, 2015 4:03 am
by mrjohnmohamed
: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?????????

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

Posted: Sat Jun 06, 2015 12:51 am
by skot
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"

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

Posted: Sat Jun 06, 2015 9:58 pm
by mrjohnmohamed
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

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

Posted: Sat Jun 13, 2015 2:41 am
by skot
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.