Adding a New line to a text file

(imported topic written by gbabbitt91)

I found an earlier post that shows how to parse through a file and change a particualr line in that file.

// store the file location
parameter "filename" = "c:\somefile.ini"
// iterate through the file replacing lines as necessary
appendfile {concatenation "%0d%0a" of ( if (it starts with "Username=") then (preceding text of first "Username=" of it) & "Username=" & (name of current user) else it ) of lines of file(parameter "filename")}

This works great but what I would like to do is modify this example so that it adds a new line to the ini file before the line containing “Username=” Im not quite sure how get the newline added. Appreciate the help

thanks

Greg

(imported comment written by jessewk)

Try something like this, replacing “line you’d like to add” with your line:

appendfile {concatenation “%0d%0a” of ( if (it starts with “Username=”) then “line you’d like to add” & “%0d%0a” & it else it ) of lines of file(parameter “filename”)}

(imported comment written by gbabbitt91)

Thanks! That worked great.