Community discussions

MikroTik App
 
richedav
Member Candidate
Member Candidate
Topic Author
Posts: 114
Joined: Mon Dec 13, 2010 12:13 am

Strip Linefeed/EOL from fetched file

Sat Oct 15, 2011 6:27 pm

Hi All

Just started to play with Scripting which is working well, except for the problem I have with a \n appearing on the end of the file I am pulling from a website

Its a very basic script, simply pulls a SSID down from the server , and sets the SSID on the WLAN1 interface if its different to that previously suppled ( to facilitate basic management of the hotspot service from a cloud based system)

If the server outputs 'test'

Mikrotk is reporting the said as 'test\n'

Theres no trim commands, so whats the best way to remove the EOL characters?

Many thanks
 
User avatar
TealFrog
just joined
Posts: 23
Joined: Sun Oct 02, 2011 11:56 am

Re: Strip Linefeed/EOL from fetched file

Sat Nov 05, 2011 9:07 am

It may be a bit late, but actually the script I posted a day before your post does something very similar to this...

http://forum.mikrotik.com/viewtopic.php?f=9&t=55738

If you want to trim the last character, then it is just a matter of doing something like:
:put [ :pick "test\n" 0 ( [ :len "test\n" ] -1 ) ];
As another example:
:local w "test\n";
:put [ :pick $w 0 ( [ :len $w ] -1 ) ];
To get characters up to the occurrence of the end of line (newline) character:
:local line "test\n";
:put [ :pick $line 0 [ :find $line "\n" ] ];
Regards.
TealFrog
 
richedav
Member Candidate
Member Candidate
Topic Author
Posts: 114
Joined: Mon Dec 13, 2010 12:13 am

Re: Strip Linefeed/EOL from fetched file

Tue Nov 15, 2011 4:52 pm

Thanks for the update - added to my cut.n.paste lists of code!

Who is online

Users browsing this forum: No registered users and 33 guests