Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How to edit a text file (remove carriage returns)

Reply
 
Old 05-22-2009   #1 (permalink)
Bre-x


 
 

How to edit a text file (remove carriage returns)

I have around 68,000 records on a text file


+File E:\JOHN_BACKUP\SCOPEFOLDER\Administration
/owner =builtin\administrators

+File E:\JOHN_BACKUP\SCOPEFOLDER\Eng
/owner =builtin\administrators

+File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN
/owner =scope\administrator


I would like to change it to:


+File E:\JOHN_BACKUP\SCOPEFOLDER\Administration /owner
=builtin\administrators

+File E:\JOHN_BACKUP\SCOPEFOLDER\Eng /owner
=builtin\administrators

+File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN /owner
=scope\administrator


I would like to remove all carriage returns, so i can import the text file
into and access database

Thank you all,


Bre-x



My System SpecsSystem Spec
Old 05-22-2009   #2 (permalink)
Paul Randall


 
 

Re: How to edit a text file (remove carriage returns)

Try opening the text file with a hex editor, like PSPad in hex view mode, or
XVI, both freely available on the internet. Line separators may be a single
carriage return character or a single line feed character or a combination
of the two. The hex editor should show you whether there is a specific
string that comes before and after the line separator you want to remove,
and you should be able to build a string in your script to match what you
want replaced (something like sTemp = "pretext" & vbCrLf & "posttext").
Then have the script read the entire file into a string and use the Replace
function to replace the old PretextLineseparatorPosttext combination with
your desired PretextSpaceorwhateverPosttext string. Then write the
newstring out to a file.

I have successfully used this technique on files as large as 38 megabytes
read as one chunk. On large files you may find Textstream.Readall to be
significantly slower than Textstream.Read(filesize), and you must use
the.Read(chunksize) method if the file contains any Chr(0) characters.

-Paul Randall

"Bre-x" <cholotron@xxxxxx> wrote in message
news:O0ZO9iu2JHA.4744@xxxxxx
Quote:

>I have around 68,000 records on a text file
>
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration
> /owner =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Eng
> /owner =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN
> /owner =scope\administrator
>
>
> I would like to change it to:
>
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration /owner
> =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Eng /owner =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN /owner
> =scope\administrator
>
>
> I would like to remove all carriage returns, so i can import the text file
> into and access database
>
> Thank you all,
>
>
> Bre-x
>

My System SpecsSystem Spec
Old 05-22-2009   #3 (permalink)
trading_jacks


 
 

Re: How to edit a text file (remove carriage returns)

On May 22, 9:22*am, "Bre-x" <cholot...@xxxxxx> wrote:
Quote:

> I have around 68,000 records on a text file
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration
> /owner * * * * * * =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Eng
> /owner * * * * * * =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN
> /owner * * * * * * =scope\administrator
>
> I would like to change it to:
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration /owner
> =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Eng /owner
> =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN /owner
> =scope\administrator
>
> I would like to remove all carriage returns, so i can import the text file
> into and access database
>
> Thank you all,
>
> Bre-x

This might work if the second line is a tab between what you want to
split. I am also not sure if you will need to add that space on line
16 of the script. Try it and post the result file and that will help
me.



Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("old.txt", 1)

strText = objTextFile.ReadAll
objTextFile.Close

arrLines = Split(strText, vbCrLf)

Set objTextFile2 = objFSO.OpenTextFile("new.txt", 2, True)

i = 1

For Each strLine in arrLines

If i mod 2 = 1 Then
objTextFile2.Write strLine & Space(1)
Else
arrsplitline = Split(strLine, vbTab)
objTextFile2.Write arrsplitline(0) & vbCrLf & arrsplitline(1) & vbCrLf
End If

i = i +1

Next
My System SpecsSystem Spec
Old 05-22-2009   #4 (permalink)
Bre-x


 
 

Re: How to edit a text file (remove carriage returns)

Thank guys


"Bre-x" <cholotron@xxxxxx> wrote in message
news:O0ZO9iu2JHA.4744@xxxxxx
Quote:

>I have around 68,000 records on a text file
>
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration
> /owner =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Eng
> /owner =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN
> /owner =scope\administrator
>
>
> I would like to change it to:
>
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration /owner
> =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Eng /owner =builtin\administrators
>
> +File E:\JOHN_BACKUP\SCOPEFOLDER\Administration\CARMEN /owner
> =scope\administrator
>
>
> I would like to remove all carriage returns, so i can import the text file
> into and access database
>
> Thank you all,
>
>
> Bre-x
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Text attachments - carriage returns inserted into attachment Live Mail
How to remove carriage returns in a text file. VB Script
Avoid "carriage return" in text file PowerShell
Preserve carriage returns in RichTextBox control .NET General
Add-Content and carriage returns PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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