i have a log file in this format...

a,b,c,d,e,f,g
a,b,c,d,e,f,g
a,b,c,d,e,f,g
a,b,c,d,e,f,g


it finish with double newline ( /n)

i need to replace the last caracther of the file, like typing a backspace.
any idea??

Re: replace string by Mythran

Mythran
Tue Nov 29 12:35:57 CST 2005


"setner" <yusretNOsPaMMINGGG@fastwebnet.it> wrote in message
news:N%0jf.25921$tc5.22687@tornado.fastwebnet.it...
>i have a log file in this format...
>
> a,b,c,d,e,f,g
> a,b,c,d,e,f,g
> a,b,c,d,e,f,g
> a,b,c,d,e,f,g
>
>
> it finish with double newline ( /n)
>
> i need to replace the last caracther of the file, like typing a backspace.
> any idea??
>

Well, read in line-by-line from the file into a line buffer (single string
variable). Remove the last character (if you read line by line, the Cr/Lf
char(s) should not be on the end of the line). Store into a temp string
variable that contains all other lines appended to each other or write to a
temporary file. When all is done, re-write the original file with the
results ;)

Mythran


Re: replace string by setner

setner
Tue Nov 29 12:49:25 CST 2005


"Mythran" <kip_potter@hotmail.comREMOVETRAIL> ha scritto nel messaggio
news:Oq%23g%23OR9FHA.808@TK2MSFTNGP09.phx.gbl...
>

> Well, read in line-by-line from the file into a line buffer (single string
> variable). Remove the last character (if you read line by line, the Cr/Lf
> char(s) should not be on the end of the line). Store into a temp string
> variable that contains all other lines appended to each other or write to
> a temporary file. When all is done, re-write the original file with the
> results ;)
>
> Mythran
>

uhmm i'm missing something?? see in this way...

have this format:
a,b,c,d,e,f,g/n
a,b,c,d,e,f,g/n
a,b,c,d,e,f,g/n
a,b,c,d,e,f,g/n

want this format:
a,b,c,d,e,f,g/n
a,b,c,d,e,f,g/n
a,b,c,d,e,f,g/n
a,b,c,d,e,f,g

if i read line by line i will find the /n caracther also al last line. maybe
i'm wrong?(there's a special command to read line by line?? )



Re: replace string by McKirahan

McKirahan
Tue Nov 29 12:59:15 CST 2005

"setner" <yusretNOsPaMMINGGG@fastwebnet.it> wrote in message
news:N%0jf.25921$tc5.22687@tornado.fastwebnet.it...
> i have a log file in this format...
>
> a,b,c,d,e,f,g
> a,b,c,d,e,f,g
> a,b,c,d,e,f,g
> a,b,c,d,e,f,g
>
>
> it finish with double newline ( /n)
>
> i need to replace the last caracther of the file, like typing a backspace.
> any idea??


Will this help? Watch for word-wrap.

Option Explicit
Const cLOG = "alogfile.log"
Dim strLOG
strLOG =
CreateObject("Scripting.FileSystemObject").OpenTextFile(cLOG,1).ReadAll
strLOG = Left(strLOG,Len(strLOG)-2)
CreateObject("Scripting.FileSystemObject").CreateTextFile(cLOG,True).Write(s
trLOG)



Re: replace string by ekkehard

ekkehard
Tue Nov 29 13:26:12 CST 2005

McKirahan wrote:
> "setner" <yusretNOsPaMMINGGG@fastwebnet.it> wrote in message
> news:N%0jf.25921$tc5.22687@tornado.fastwebnet.it...
>
>>i have a log file in this format...
>>
>>a,b,c,d,e,f,g
>>a,b,c,d,e,f,g
>>a,b,c,d,e,f,g
>>a,b,c,d,e,f,g
>>
>>
>>it finish with double newline ( /n)
>>
>>i need to replace the last caracther of the file, like typing a backspace.
>>any idea??
>
>
>
> Will this help? Watch for word-wrap.
>
> Option Explicit
> Const cLOG = "alogfile.log"
> Dim strLOG
> strLOG =
> CreateObject("Scripting.FileSystemObject").OpenTextFile(cLOG,1).ReadAll
> strLOG = Left(strLOG,Len(strLOG)-2)
> CreateObject("Scripting.FileSystemObject").CreateTextFile(cLOG,True).Write(s
> trLOG)
>
>
Nearly the same, but emphasizes the problem of \n vs. \r\n:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sFSpec : sFSpec = ".\test.log"
Dim nTail : nTail = 1 ' for \n, could be 2 for \r\n
Dim sText

sText = oFS.OpenTextFile( sFSpec ).ReadAll
oFS.CreateTextFile( sFSpec + ".cut", True ).Write Left( sText, Len( sText ) - nTail )


Re: replace string by setner

setner
Tue Nov 29 13:46:44 CST 2005

>
>
> Will this help? Watch for word-wrap.
>
> Option Explicit
> Const cLOG = "alogfile.log"
> Dim strLOG
> strLOG =
> CreateObject("Scripting.FileSystemObject").OpenTextFile(cLOG,1).ReadAll
> strLOG = Left(strLOG,Len(strLOG)-2)
> CreateObject("Scripting.FileSystemObject").CreateTextFile(cLOG,True).Write(s
> trLOG)
>
>

i could only say thanks!! works great!! :)



Re: replace string by Mythran

Mythran
Tue Nov 29 16:00:52 CST 2005


"setner" <yusretNOsPaMMINGGG@fastwebnet.it> wrote in message
news:Qo1jf.25979$tc5.14759@tornado.fastwebnet.it...
>
> "Mythran" <kip_potter@hotmail.comREMOVETRAIL> ha scritto nel messaggio
> news:Oq%23g%23OR9FHA.808@TK2MSFTNGP09.phx.gbl...
>>
>
>> Well, read in line-by-line from the file into a line buffer (single
>> string variable). Remove the last character (if you read line by line,
>> the Cr/Lf char(s) should not be on the end of the line). Store into a
>> temp string variable that contains all other lines appended to each other
>> or write to a temporary file. When all is done, re-write the original
>> file with the results ;)
>>
>> Mythran
>>
>
> uhmm i'm missing something?? see in this way...
>
> have this format:
> a,b,c,d,e,f,g/n
> a,b,c,d,e,f,g/n
> a,b,c,d,e,f,g/n
> a,b,c,d,e,f,g/n
>
> want this format:
> a,b,c,d,e,f,g/n
> a,b,c,d,e,f,g/n
> a,b,c,d,e,f,g/n
> a,b,c,d,e,f,g
>
> if i read line by line i will find the /n caracther also al last line.
> maybe i'm wrong?(there's a special command to read line by line?? )
>

Oops, you said file, not line ;) Read in the file, use the Left function
passing in Len(contentsoffile) - 1 as the count argument of Left...then
write out the contents ;) That's a fast way for not-too-big files...

Mythran