Change word in comment

Hi,

I would need a script that would change one word in the comment, which is always the same, while the other words should remain unchanged.

like this
Roterboard now
set [ find default-name=sfp1 ] comment=lalalal_WORDBEFORElalalal name=Gi0/1
set [ find default-name=sfp2 ] comment=vavavav
WORDBEFOREvavavav name=Gi0/2
set [ find default-name=sfp3 ] comment=dvdvdvd
WORDBEFORE_dvdvdvd name=Gi0/3

Roterboard after script
set [ find default-name=sfp1 ] comment=lalalal_WORDAFTERlalalal name=Gi0/1
set [ find default-name=sfp2 ] comment=vavavav
WORDAFTERvavavav name=Gi0/2
set [ find default-name=sfp3 ] comment=dvdvdvd
WORDAFTER_dvdvdvd name=Gi0/3

The script should search for the interface with the keyword “WORDBEFORE” in the comment and change it to “WORDAFTER


Thanks for your help :slight_smile:

and what is needed? it’s easy!

search tag # rextended Search and replace function:

:global searep do={
    :local input [:tostr $1] ; :local search  [:tostr $2] ; :local replace [:tostr $3]
    :local start -1 ; :local tmppos 0 ; :local sx "" ; :local dx ""
    :while ([:typeof [:find $input $search $start]] = "num") do={
        :set tmppos [:find $input $search $start]
        :set sx     [:pick $input 0 $tmppos]
        :set dx     [:pick $input ($tmppos + [:len $search]) [:len $input]]
        :set start  ([:len "$sx$replace"] - 1)
        :set input  "$sx$replace$dx"
    }
    :return $input
}

How to use that function:
/interface
{
:local searchthis “WORDBEFORE”
:local replcwthis “WORDAFTER”
:foreach item in=[find where !dynamic and type=“ether” and comment~$searchthis] do={
:put [get $item comment]
set $item comment=[$searep [get $item comment] $searchthis $replcwthis]
:put [get $item comment]
}
}

Hi,

I tried to run script but result is empty comment...
What i did wrong?

Tnx


Check if these three conditions are met:

in=[find where !dynamic and type="ether" and comment~$searchthis]

BR.

interface prin where !dynamic and type=“ether”


Flags: D - dynamic, X - disabled, R - running, S - slave

NAME TYPE ACTUAL-MTU L2MTU MAX-L2MTU MAC-ADDRESS

Gi1/1 ether 1500 1598 9498 D4:CA:6D:41:EC:C0
1 S Gi1/2 ether 1500 1598 9498 D4:CA:6D:41:EC:C1
2 S Gi1/3 ether 1500 1598 9498 D4:CA:6D:41:EC:C2
3 S ;;; lalalal_WORDBEFORE_lalalal
Gi1/4 ether 1500 1598 9498 D4:CA:6D:41:EC:C3
4 S Gi1/5 ether 1500 1598 9498 D4:CA:6D:41:EC:C4
5 S Gi1/6 ether 1500 1598 9498 D4:CA:6D:41:EC:C5
6 Gi1/7 ether 1500 1598 9498 D4:CA:6D:41:EC:C6
7 Gi1/8 ether 1500 1598 9498 D4:CA:6D:41:EC:C7
8 Gi1/9 ether 1500 1598 9498 D4:CA:6D:41:EC:C8
9 Gi1/10 ether 1500 1598 9498 D4:CA:6D:41:EC:C9
10 Gi1/11 ether 1500 1600 9500 D4:CA:6D:41:EC:CA
11 Gi1/12 ether 1500 1600 9116 D4:CA:6D:41:EC:CB
12 Gi1/13 ether 1500 1600 9116 D4:CA:6D:41:EC:CC




you paste both function and example on terminal, or only the example that use the function?

If you do not paste first the function, how to use it?

You have blank results also with this?

:foreach item in=[/interface find where !dynamic and type="ether" and comment~"WORDBEFORE"] do={ :put [/interface get $item comment] }

With this code nothing happens

/interface
{
:local searchthis "WORDBEFORE"
:local replcwthis "WORDAFTER"
    :foreach item in=[/interface find where !dynamic and type="ether" and comment~"WORDBEFORE"] do={ :put [/interface get $item comment] }
:put [get $item comment]
        set $item comment=[$searep [get $item comment] $searchthis $replcwthis]
:put [get $item comment]
    }
}

I can give you access to one routerborad if you want to try?

You read what you quoted?

You must use both script at same time, or why I write the function over the example, uselessly?

Ahh, sry... i now undstand the script, it works! Thanks a lot!

I have tried but failed.

Information:
(vc-138-05.06.24-) This is the code when the hotspot user is created, it doesn't need to be changed.
(SELLERCODE) functions to calculate the number of hotspot users based on the seller code name, no need to change it.
(ACTIVE) This serves to indicate that the hotspot user has not been used, but if the hotspot user has already been used, ACTIVE is changed to USED.

I need to change the hotspot user comment
from "vc-138-05.06.24-SELLERCODE ACTIVE"
to "vc-138-05.06.24-SELLERCODE USED"

Notes:
Between SELLERCODE ACTIVE or SELLERCODE USED, in the middle there is a space as a separator.

Useless info if you not provide what you have done, since the example change ethernet comment, not user hotspot comment.