Community discussions

MikroTik App
 
changeip
Forum Guru
Forum Guru
Topic Author
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

get contents of a file

Wed Mar 22, 2006 10:44 pm

Is it possible to loop thru rows of a file?

[admin@MikroBot] file> :put [/file get countries.txt name]
countries.txt

[admin@MikroBot] file> :put [/file get countries.txt contents]

The second command does nothing ... I would assume 'contents' means whats in the file but nothing comes out. I'm trying to take a file with a list of IP ranges and run a command using :foreach on them, but the get contents doesn't seem to work.

Sam
 
eflanery
Member
Member
Posts: 376
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Thu Mar 23, 2006 6:08 am

Well, it does seem to give the contents:

[admin@EricsHome] file> :put [/file get someips.txt contents ]
1.2.3.4
100.200.200.100
4.3.2.1

But, it does appear to be crlf terminated in the DOS style, and when I try looping through it with :foreach, I get this:

[admin@EricsHome] file> :foreach x in [/file get someips.txt contents ] do={:put ($x . $x)}
1.2.3.4
100.200.200.100
4.3.2.1
1.2.3.4
100.200.200.100
4.3.2.1

So, you would probably have to do some ":find"-ing, and some ":pick"-ing to make it useful.

Hey MT dudes, how about some sort of :grep, :sed, and :awk. :twisted:

--Eric
 
changeip
Forum Guru
Forum Guru
Topic Author
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Thu Mar 23, 2006 8:14 am

Hmm... seems that it doesn't like big files. I've used the same file format for both and I can get them to work if they aren't as long. I will see if I can find a reason for it. Maybe the buffer can only read a certain amount of lines and then it dies? I will see what I can find.

Sam

Who is online

Users browsing this forum: Google [Bot] and 52 guests