Batch \ VB scripting help needed

Associate
Joined
24 Oct 2002
Posts
2,417
Location
Cork, Ireland
Hi - I have a txt file with stuff like the following in it...

04/04/12;14:12:34;65;38;2;50;100
04/04/12;14:12:36;66;38;2;50;100
04/04/12;14:12:38;65;38;2;50;100
04/04/12;14:12:40;65;38;2;50;100
04/04/12;14:12:42;64;38;2;50;100
04/04/12;14:12:44;65;38;2;50;100
04/04/12;14:12:46;64;38;2;50;100
05/04/12;10:28:08;9;10;2;50;18
05/04/12;10:28:10;8;10;2;50;0
05/04/12;10:28:12;9;10;2;50;0
05/04/12;10:28:14;12;9;2;50;0
05/04/12;10:28:16;16;7;2;50;0
05/04/12;10:28:18;23;5;2;50;7
05/04/12;10:28:20;29;4;2;50;46
05/04/12;10:28:22;36;4;2;50;100

etc..

I have to go in to this file and make a series of other text files for each date listed (eg. 05-04-12.txt)

I have a done a little bit of scripting in the past but I'm not getting anywhere.

Would anyone be kind enough to point me in the right direction on automating this?

Many thanks,

Luke
 
Last edited:
I have just written a lot of text and binary file manipulation. If you can tell me exactly what you want I can probably modify some of my code in send it over.
 
Code:
Args = WScript.Arguments.Count

If Args = 1 Then
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set File = FSO.OpenTextFile(WScript.Arguments.Item(0))

	Do While Not File.AtEndOfStream
		Line = File.ReadLine()
		Data = Split(Line, ";", 2)
		FileName = Replace(Data(0), "/", "-") & ".txt"
		If FSO.FileExists(FileName) = False Then
			FSO.CreateTextFile FileName
		End If
	Loop
End If

It just creates a bunch of empty files. If you need to add something to it (like the rest of the line?) it should be pretty simple

Usage <script_name>.vbs <input.txt>
 
Thanks for your help guys. Unfortunately I completely failed to explain properly.

Ideally the script would turn this..

04/04/12;14:12:34;65;38;2;50;100
04/04/12;14:12:36;66;38;2;50;100
04/04/12;14:12:38;65;38;2;50;100
04/04/12;14:12:40;65;38;2;50;100
04/04/12;14:12:42;64;38;2;50;100
04/04/12;14:12:44;65;38;2;50;100
04/04/12;14:12:46;64;38;2;50;100
05/04/12;10:28:08;9;10;2;50;18
05/04/12;10:28:10;8;10;2;50;0
05/04/12;10:28:12;9;10;2;50;0
05/04/12;10:28:14;12;9;2;50;0
05/04/12;10:28:16;16;7;2;50;0
05/04/12;10:28:18;23;5;2;50;7
05/04/12;10:28:20;29;4;2;50;46
05/04/12;10:28:22;36;4;2;50;100

into..

04-04-12.txt containing
04/04/12;14:12:34;65;38;2;50;100
04/04/12;14:12:36;66;38;2;50;100
04/04/12;14:12:38;65;38;2;50;100
04/04/12;14:12:40;65;38;2;50;100
04/04/12;14:12:42;64;38;2;50;100
04/04/12;14:12:44;65;38;2;50;100
04/04/12;14:12:46;64;38;2;50;100

and 05-04-12.txt containing
05/04/12;10:28:08;9;10;2;50;18
05/04/12;10:28:10;8;10;2;50;0
05/04/12;10:28:12;9;10;2;50;0
05/04/12;10:28:14;12;9;2;50;0
05/04/12;10:28:16;16;7;2;50;0
05/04/12;10:28:18;23;5;2;50;7
05/04/12;10:28:20;29;4;2;50;46
05/04/12;10:28:22;36;4;2;50;100
 
This PowerShell script should do what you want:

Code:
#Customise Vars
$Folder = "C:\Test\"
$File = $Folder + "doc1.txt"

$FileContent = gc $File
$FileContentGrouping = $FileContent | Group {$_.SubString(0, 8)}

foreach ($Grouping in $FileContentGrouping)
{
	$NewFileName = $Folder + ($Grouping.Name -Replace "/","-") + ".txt"
	$Grouping.Group | Out-File $NewFileName
}
 
Back
Top Bottom