Modo de empleo
Código [Seleccionar]
CScript.exe ".\Script.vbs" ".\Archivo1.txt" ".\Archivo2.txt" "etc..."
Source
Código (vbnet) [Seleccionar]
' Example: RegEx capture in textfile, By Elektro
Option Explicit
Dim args, arg, _
outPath, fullpath, fileName, fileExt, _
fso, file, fileContent, _
rgx, rgxMatches, rgxMatch, rgxValue
Set args = WScript.Arguments
If args.Count = 0 Then
Wscript.Echo("Any filepath specified.")
Wscript.Quit(1)
End If
outPath = ".\Output\"
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(outPath) Then
Call fso.CreateFolder(outPath)
End If
' El primer grupo de esta expresión captura el string "cash out:" plus el valor decimal.
' El cuarto grupo de esta expresión captura el valor decimal.
Set rgx = New RegExp
rgx.Pattern = "Cash(\s+)?out(\:)?(\s+)?([\d\.]+)"
rgx.IgnoreCase = True
rgx.Global = True
For Each arg in args
fullPath = fso.GetAbsolutePathName(arg)
fileName = fso.GetBaseName(fullPath)
fileExt = fso.GetExtensionName(fullPath)
fileContent = fso.OpenTextFile(fullPath, 1).ReadAll
Set rgxMatches = rgx.Execute(fileContent)
Set file = fso.CreateTextFile(outPath & "\" & fileName & "_new" & "." & fileext)
Wscript.Echo("[+] Processing file: " & fullPath)
For Each rgxMatch in rgxMatches
rgxValue = rgxMatch.Submatches(3)
Wscript.Echo(rgxValue)
Call file.WriteLine("Cash Out: " & rgxValue)
Next
file.Close
Next
Wscript.Quit(0)
Output
- .\Archivo1.txt
Código [Seleccionar]
asdadasdasdasd asdsadas asdasdasd cash out: 1.97 asdasdas asdasda
asdadasdasdasd asdsadas asdasdasd cash out: 212.34 asdasdas asdasda
- .\Outpu\Archivo1_new.txt
Código [Seleccionar]
Cash Out: 1.97
Cash Out: 212.34
Saludos