File Manipulation

Hi All,

I use /tool fetch to get a file from a remote server and I am able to read the contents by doing “:global text [/file get filename contents]”. The file consists of the following info, for example.

wlan-personal.ssid Personal
wlan-personal.channel 10
wlan-personal.mac 00:01:02:03:04:05
wlan-students.ssid Student
wlan-students.channel 4
wlan-students.mac 06:07:08:09:0a:0b
wan-gpon.username user
wan-gpon.password password

How do I read a specific field and its value? For example, I just want to know what the value of wlan-students.ssid is.


Thank you very much.
Vincent

Give this a try. It finds “wlan-students.ssid”, then based on the following space and the new line “\r\n” it determines the value. Depending on how the file is saved, “\r\n” might need to be “\n”.

The starting and ending brackets {} are for testing in the terminal, otherwise they can be removed in your final script.
{
:local text [/file get filename contents]
:local pos1 [:find $text “wlan-students.ssid”]
:local pos2 ([:find $text " " $pos1] + 1)
:local pos3 [:find $text “\r\n” $pos1]
:if ([:len $pos3] = 0) do={
:set pos3 [:len $text]
}
:local value [:pick $text $pos2 $pos3]
:put $value
}

Thanks Skot! The code works very well.