Sign in to follow this  
Followers 0
pbecks1963

Making a csv out off a plain txt

4 posts in this topic

#1 ·  Posted (edited)

Hello,

I have a plain text file (large!) with data in it. Looks like this example:

********************************************************************************

USER: JOHN

IP Configuration:

Windows IP-configuratie

Host-naam . . . . . . . . . . . .: fghfgh

Primair DNS-achtervoegsel. . . . .: hdfgfh

Knooppunttype: . . . . . . . . . .: dfghgf

IP-routering ingeschakeld. . . . .: fdgh

WINS-proxy ingeschakeld . . . . . : nefghfe

DNS-achtervoegselzoeklijst. . . . : fghdfg

Applications:

3.46.0

AHV content for Acrobat and Flash 1

Adobe AIR 2.0.4.13090

Adobe AIR 2.0.4.13090

Cards

MsWord

MsExcel

USER: George

IP Configuration:

Windows IP-configuratie

Host-naam . . . . . . . . . . . .: fghfgh

Primair DNS-achtervoegsel. . . . .: hdfgfh

Knooppunttype: . . . . . . . . . .: dfghgf

IP-routering ingeschakeld. . . . .: fdgh

WINS-proxy ingeschakeld . . . . . : nefghfe

DNS-achtervoegselzoeklijst. . . . : fghdfg

Applications:

3.46.0

MsWord

MsExcel

*************************************************************

What i want is to change the text file into a csv-file (so that i can import it into MsExcel) So what i need to do is:

-remove all blank lines

-Put a comma behind all lines and merge the lines together (remove <ENTER>)

-place all the data of 1 USER on 1 line. (so, preceding the line that start with "USER", there has to be a <ENTER>

Note: one USER can have more data/lines in this text file then another USER.

Can someone help me with making this autoit-script?

Edited by pbecks1963

Share this post


Link to post
Share on other sites



For starters from the Help file.

$file = FileOpen("test1.txt", 0)
$Count = 0
$alllines = "Begin Here ====="
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
    $count = $Count + 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$line = $line & ","
MsgBox(0, "Line read: "& $Count, $line)
$alllines = $alllines & $line
Wend
MsgBox(0, "Lines read: ", $alllines)
FileClose($file)

Share this post


Link to post
Share on other sites

Which application is producing the output? Another AU3 script?

If yes, it is easier to modify that code to produce the output format you want.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Hello,

I actually did it like this:

********************************

$Output = ""

;copy all log files into one big file

runwait( @comspec & " /c copy d:\current\*.log d:\current\merged.txt","",@SW_HIDE)

$szFile = "d:\current\merged.txt"

;search & replace

$szText = FileRead($szFile,FileGetSize($szFile))

$szText = StringReplace($szText, ",",";")

$szText = StringReplace($szText, @CRLF, ",")

$szText = StringReplace($szText, @CR, ",")

$szText = StringReplace($szText, @LF, ",")

$szText = StringReplace($szText," Host-naam . . . . . . . . . . . .:", ",")

$szText = StringReplace($szText, "USER:",@CRLF&"USER:")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, " ", " ")

$szText = StringReplace($szText, "IP Configuration: ","")

$szText = StringReplace($szText, "Windows IP-configuratie","")

FileDelete($szFile)

FileWrite($szFile,$szText)

***************************************************

I am not completely happy with it but it gets the job done (somewhat)

Share this post


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
Sign in to follow this  
Followers 0