Hello:

I am working on a script that takes a .txt log file and puts it in a
database. I have everything working on this script with the exception of one
small item: Date Conversion (which I am manually doing at this time).

I need to replace the format of the date (YYYY-MM-DD) in the text file to be
the same format as the filename.

Filename:
11-27-2005-PingLogs.txt

Sample text:
2005-11-27 00:00:47,192.168.2.1,Ping: No Response
2005-11-27 00:00:47,192.168.2.1,Ping: No Response
2005-11-27 00:00:47,192.168.2.1,Ping: No Response
2005-11-27 00:00:47,192.168.2.1,Ping: No Response
2005-11-27 00:00:47,192.168.2.1,Ping: No Response

Converted date:
11-27-2005,00:00:47,192.168.2.1,Ping: No Response
11-27-2005,00:00:47,192.168.2.1,Ping: No Response
11-27-2005,00:00:47,192.168.2.1,Ping: No Response
11-27-2005,00:00:47,192.168.2.1,Ping: No Response
11-27-2005,00:00:47,192.168.2.1,Ping: No Response

How can I find each occurrence of the YYYY-MM-DD format and replace it with
the same format in the filename?

P.S. I cannot get the date to export any other way to the log file.

Thanks
CADstillo

Re: Replace text within file based on file name by Santos

Santos
Mon Nov 28 23:08:47 CST 2005

I'm sure there is a better way to do this but (watch for word wrap):

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\11-27-2005-pinglogs.txt",
ForReading)

Do While objTextFile.AtEndOfStream <> True
arrPINGdate = split(objTextFile.Readline,"-",-1,1)
arrPINGINFO = split(arrPINGdate(2)," ",-1,1)
Wscript.Echo arrPINGdate(1) & "-" & arrPINGINFO(0) & "-" &
arrPINGdate(0) & "," & arrPINGINFO(1) & arrPINGINFO(2) & arrPINGINFO(3)
i = i + 1
Loop

"Cadstillo" <Cadstillo@discussions.microsoft.com> wrote in message
news:DA566519-9275-4C9C-A6B0-402B95CAB585@microsoft.com...
> Hello:
>
> I am working on a script that takes a .txt log file and puts it in a
> database. I have everything working on this script with the exception of
> one
> small item: Date Conversion (which I am manually doing at this time).
>
> I need to replace the format of the date (YYYY-MM-DD) in the text file to
> be
> the same format as the filename.
>
> Filename:
> 11-27-2005-PingLogs.txt
>
> Sample text:
> 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
>
> Converted date:
> 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
>
> How can I find each occurrence of the YYYY-MM-DD format and replace it
> with
> the same format in the filename?
>
> P.S. I cannot get the date to export any other way to the log file.
>
> Thanks
> CADstillo
>



Re: Replace text within file based on file name by Cadstillo

Cadstillo
Mon Dec 12 10:32:02 CST 2005

Thanks
--
Cadstillo



"Santos Soler" wrote:

> I'm sure there is a better way to do this but (watch for word wrap):
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile("c:\temp\11-27-2005-pinglogs.txt",
> ForReading)
>
> Do While objTextFile.AtEndOfStream <> True
> arrPINGdate = split(objTextFile.Readline,"-",-1,1)
> arrPINGINFO = split(arrPINGdate(2)," ",-1,1)
> Wscript.Echo arrPINGdate(1) & "-" & arrPINGINFO(0) & "-" &
> arrPINGdate(0) & "," & arrPINGINFO(1) & arrPINGINFO(2) & arrPINGINFO(3)
> i = i + 1
> Loop
>
> "Cadstillo" <Cadstillo@discussions.microsoft.com> wrote in message
> news:DA566519-9275-4C9C-A6B0-402B95CAB585@microsoft.com...
> > Hello:
> >
> > I am working on a script that takes a .txt log file and puts it in a
> > database. I have everything working on this script with the exception of
> > one
> > small item: Date Conversion (which I am manually doing at this time).
> >
> > I need to replace the format of the date (YYYY-MM-DD) in the text file to
> > be
> > the same format as the filename.
> >
> > Filename:
> > 11-27-2005-PingLogs.txt
> >
> > Sample text:
> > 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> > 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> > 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> > 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> > 2005-11-27 00:00:47,192.168.2.1,Ping: No Response
> >
> > Converted date:
> > 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> > 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> > 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> > 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> > 11-27-2005,00:00:47,192.168.2.1,Ping: No Response
> >
> > How can I find each occurrence of the YYYY-MM-DD format and replace it
> > with
> > the same format in the filename?
> >
> > P.S. I cannot get the date to export any other way to the log file.
> >
> > Thanks
> > CADstillo
> >
>
>
>