script cannot running if file log.0.txt to big when tried to read each line

halo i have problem when read dan put result from large size of /file log.0.txt
this is my script to convert MMM/dd/yyyy to yyyy/mm/dd each line in log.0.txt

Initialize variables

:global logFileContents [/file/get ppp_log.0.txt contents]
:global logarray
:global currentLine ""
:global formattedDate

Membagi line di /file/get ppp_log.0.txt

:for i from=0 to=([:len $logFileContents] - 1) do={
:local char [:pick $logFileContents $i]
:if ($char = "\n") do={
:set logarray ($logarray, $currentLine)
:set currentLine ""
} else={
:set currentLine ($currentLine . $char)
}
}

Filter and format log entries

:foreach logEntry in=$logarray do={
:local month [:pick $logEntry 0 4]
:local day [:pick $logEntry 5 6]
:local year [:pick $logEntry 8 10]
#:local time [:pick $logEntry 12 19]
#:local message [:pick $logEntry 21 [:len $logEntry]]
:local monthName ""
:if ($month = "Jan") do={:set monthName "01"}
:if ($month = "Feb") do={:set monthName "02"}
:if ($month = "Mar") do={:set monthName "03"}
:if ($month = "Apr") do={:set monthName "04"}
:if ($month = "May") do={:set monthName "05"}
:if ($month = "Jun") do={:set monthName "06"}
:if ($month = "Jul") do={:set monthName "07"}
:if ($month = "Aug") do={:set monthName "08"}
:if ($month = "Sep") do={:set monthName "09"}
:if ($month = "Oct") do={:set monthName "10"}
:if ($month = "Nov") do={:set monthName "11"}
:if ($month = "Dec") do={:set monthName "12"}

:set formattedDate ($year . "-" . $monthName . "-" . $day. "\n")
:put [$formattedDate]
}

:put [$formattedDate]
and i have some error of this line :set formattedDate ($year . "-" . $monthName . "-" . $day. "\n")[/color]

so the problem:

  1. script cannot running if file log.0.txt to big
  2. error of this line :set formattedDate ($year . "-" . $monthName . "-" . $day. "\n")

You can only read a small file into memory at once

Using the get command, it is possible to retrieve file contents only from files up to 60KB in size

Get file contents

Need to use “file/read” instead of “file/get”.

I’d probably try to do this kind of log digestion on a remote host instead of a router with limited memory/cpu.