Hello ,
is there any why to add new line to file without delete the old one?
if I use this command -
/file set test.txt contents="123"
I will get in test.txt 123
and if I wan to add in line 2 “456” - how can I do this?
is it even possible?
so after i run the command twice I will see in test.txt
123
456
Despite the fact that the Linux kernel supports appending to files, RouterOS doesn’t expose that.
To append to a file, you need to instead get the current contents, concatenate the new contents onto it, and write out the full new contents.
e.g.
:local contents [/file get test.txt contents]
:set contents ($contents . "123")
/file set test.txt contents=$contents
O.K. - now its good , thanks
and if I want to go down a line every new entry
so it will be like
123
456
and not 123 456
how can I do this ? I have try to use “/n”
Thanks ,
Yes… Well, “\n”, not “/n”, but yes.
I have try both
maybe I’m writing something wrong?
:global test [/file get test.txt contents]
:set test ($test . "\n newline \n")
:file set test.txt contents=$test
The new lines are not visible in Notepad, if that’s where you’re trying to view the file. Windows uses “\r\n” for its new lines.
(also, you really shouldn’t be using a :global variable for this)
yes - now it’s working
Thanks ,
the global is just I could see what am I doing
in the final script it will be “:local”
Thanks again ,
Just a follow up on this old post , How can I ensure new data is displayed as a individual line rather than a concatenate of a existing line ?