-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfileparser.au3
93 lines (87 loc) · 2.4 KB
/
fileparser.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author: biodrone
Version: 0.0.2
Script Function:
Script to parse through text files
#ce ----------------------------------------------------------------------------
#include <Array.au3>
#include <File.au3>
Main ()
Func Main()
Global $tarfile = "C:\antisec.txt"
Global $newfile = StringMid($tarfile, 1, StringLen($tarfile) - 4) & "-parsed.txt"
Global $linecount = 0
Global $i = 0
Global $j = 0
Global $k = 0
Global $l = 0
Global $m = 0
_FileCreate($newfile)
CheckFile()
Parse()
EndFunc
; checks that the file is parsable
Func CheckFile()
If FileExists($tarfile) = 0 Then
MsgBox(0, 'File Not Found', 'Sorry, File Not Found!')
Else
ConsoleWrite("File Exists" & @CR)
EndIf
If StringInStr($tarfile, '.txt') = 0 Then
MsgBox('Incorrect Format', 'Sorry, File Format Must Be .txt')
Else
ConsoleWrite("File Format OK" & @CR)
EndIf
If @error = 0 Then
; find the lines in the file to set max array limits
$linecount = _FileCountLines($tarfile)
ConsoleWrite('Lines in file = ' & $linecount & @CR)
Else
Exit
EndIf
EndFunc
; this parses the file
Func Parse()
$email = ""
$id = ""
$pass = ""
$user = ""
$start = 1
$end = 0
$count = 1
Local $delim = ',' ; change this for a different char between fields (read)
FileOpen($tarfile, 0)
For $m = 1 to $linecount
$alldets = StringReplace(FileReadLine($tarfile, $m), '"', '')
While $count <= 4
If $start = 0 Then
$end = StringInStr($alldets, $delim, 0,$count + 1)
Else
$end = StringInStr($alldets, $delim, 0,$count)
EndIf
Select
Case $count = 1
$email = StringMid($alldets, $start, $end-$start)
Case $count = 2
$id = StringMid($alldets, $start, $end-$start)
Case $count = 3
$pass = StringMid($alldets, $start, $end-$start)
Case $count = 4
$user = StringMid($alldets, $start, $end-$start)
EndSelect
$start = $end + 1
$count += 1
WEnd
$count = 0
Write($email, $id, $pass, $user)
Next
FileClose($newfile)
EndFunc
; write to the file
Func Write($one, $two, $three, $four)
Local $delim = ';' ; change this for a different char between fields (written)
Local $writestring = $one & $delim & $two & $delim & $three & $delim & $four & @CR
FileOpen($newfile, 1)
FileWrite($newfile, $writestring)
EndFunc