Jump to content

txt file read by line and then output to new line on csv file.

Recommended Posts

;initial data.txt example below
;data in the source file will be in formats like below, where commas
;present it will already have apostrophes so it will not affect the output csv file.
;"Line, 2"
;"I am line, 3"
;Line 5
#include <array.au3>
#include <file.au3>
Local $sOutput = "New Line" & ","
Local $hFile = "initialdata.txt" ; Path to file
$hFile = FileOpen($hFile, 0)
If $hFile = -1 Then _ErrorMsg("Unable to open text file.")
Local $sData = FileRead($hFile)
If @error Then _ErrorMsg("Unable to read text file.")
$sOutput &= $sData ; Concatenate
Func _ErrorMsg($sMessage)
    MsgBox(0, "Error", $sMessage)
Local $file = FileOpen("test.txt", 1)
; Check if file opened for writing OK
If $file = -1 Then
     MsgBox(0, "Error", "Unable to output file test.txt")
FileWriteLine($file, $sData)
FileClose($file, $hFile)
Hi guys, This is my first post on this forum, I usually manage to work out whatever scripts I need from your helpful advice, however on this occasion I am a bit stuck, I have tried to write a script which will read a simple txt file, group each line together onto a single line with a comma to separate them and output the result to a csv file onto a new line ( output file will already exist ) I will try to attach what I have already below. Any help would be great thank you. ;)



Link to post
Share on other sites

Hi autoBert,

Thank you for your advice, I have been looking into using _ReplaceStringInFile however it seems to me that I could only replace things already in the file, I seem to be having more trouble with the new variables getting written into a new file, Im sure I have done correctly, or almost correctly but I cant seem to figure out where I have gone wrong.

Thank you for your help

Kindest Regards


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...