hello i need help

I already know, as I told you it's not supported, the user is using RouterOS 6, not RouterOS 7.


Yes, near for sure, but is better check... Is not the first time that I have this problem if the app write the characters as UTF-8 instead of ASCII-7bit....
(instead "password" is writed "password"....


For sure, but I must report what I see.


Is better to set on one variable or "\r\n" or only "\n" based if you [:find $xxx "\r\n"] is present or not....
Less calcs if the list is huge.....

Can't find he is mentioning that or you somehow see that from winbox screenshot.

I will leave it like that to cover both line endings robustly unless this script needs to executed in some infinite loop to be more optimized :slight_smile:
Here my final script with username trim and small correction for proper handling \r at the end, checking for unsupported characters is still needed if someone is willing to do that and correcting regex if really needs to be executed on RouterOS 6:

:local profile "all"
:local fileName "user_credentials.txt"

:local fileCnt [/file get $fileName contents]
:local fileLen [:len $fileCnt]
:local lineLen 0
:local prevLineLen 0
:local lineCnt 0
:local line ""
:local notBlank ".*\\S.*"
:local uTokenEnd " &"
:local uTokenLen [:len "username= "]
:local pTokenLen [:len "passowrd= "]
:local sepLen [:len " & "]
:local nl "\n"
:local cr "\r"
:local space " "
:local empty ""

:while ($lineLen < $fileLen) do={
  :set lineLen [:find $fileCnt $nl $prevLineLen]
  :if ([:len $lineLen] = 0) do={ :set lineLen $fileLen }
  :set line [:pick $fileCnt $prevLineLen $lineLen]
  :set prevLineLen ($lineLen + 1)

  :if ($line != $cr) do={
    :local username [:pick $line $uTokenLen [:find $line $uTokenEnd]]

    if ($username ~ $notBlank) do={
      :local spPos [:find $username $space]
      if ($spPos > 0) do={ :set username [:pick $username 0 $space] }
      :local password [:pick $line ($uTokenLen + [:len $username] + $sepLen + $pTokenLen) $lineLen]
      :local retPos [:find $password $cr]
      if ($retPos > 0) do={ :set password [:pick $password 0 $retPos] }

      if ($password != $empty) do={
        /ip/hotspot/user add name=$username password=$password profile=$profile
      }
    }
  }
}

/file remove $fileName

Thank you very much to both of you
optio - rextended

Np, you can check for invalid characters in user/pass in Telegram bot code and notify to user before adding into file.
Regarding regex in script, as rextended mentioned, if you have ROS 6 this needs correction or just adapt bot code so that cannot hapen and remove that check in script.

Well, thank you very much, but I’m not very good at writing scripts and I don’t speak English I use Google Translate and it doesn’t support my language very well And the script you put for you I put but still did not work again thanks for taking your time

It’s not working I guess because either you are using RouterOS 6.x (regex issue) or input file is not in exact format as in OP screenshot. I don’t own ROS 6 device so I cannot properly test it if ROS version is the issue.
Good luck.

i understand thanks A lot optio