We help IT Professionals succeed at work.

Need a script to remove tab characters from txt file

DebbieFost
DebbieFost asked
on
I have a text file that is tab delimited, and I need to have a script that I schedule to execute and remove tabs from this file.
Comment
Watch Question

Author

Commented:
Oh...and I also need the script to be able to remove quotes (") from the txt file again.

Thanks for any assistance.
Hi Debbie

The first script removed the " and the second removes the Tabs. Make sure to save them in two separate vbs files.
'====================================================================
'					REMOVES QUOTES
'====================================================================

Dim strAllLines,strTxtFile,strMatch,objFSO,objFile,strNewText
Const ForReading = 1
Const ForWriting = 2
	
strTxtFile = "TEXT FILE PATH"
strMatch = Chr(34)
strNewText = ""

'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strTxtFile, ForReading)
strAllLines = objFile.ReadAll
objFile.Close

strNewText = Replace(strAllLines,strMatch,strNewText)

Set objFile = objFSO.OpenTextFile(strTxtFile, ForWriting)
objFile.WriteLine(strNewText)
objFile.Close

'====================================================================
'					END OF REMOVES QUOTES
'====================================================================



'====================================================================
'					REMOVES TABS
'====================================================================


Dim strAllLines,strTxtFile,strMatch,objFSO,objFile,strNewText
Const ForReading = 1
Const ForWriting = 2
	
strTxtFile = "TEXT FILE PATH"
strTxtFile = "C:\Documents and Settings\soullm01\Desktop\1.txt"
strMatch = vbTab
strNewText = ""

'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strTxtFile, ForReading)
strAllLines = objFile.ReadAll
objFile.Close

strNewText = Replace(strAllLines,strMatch,strNewText)

Set objFile = objFSO.OpenTextFile(strTxtFile, ForWriting)
objFile.WriteLine(strNewText)
objFile.Close

'====================================================================
'					END OF REMOVES TABS
'====================================================================

Open in new window

Use this one, as there is an error on the previous script
'====================================================================
'					REMOVES QUOTES
'====================================================================

Dim strAllLines,strTxtFile,strMatch,objFSO,objFile,strNewText
Const ForReading = 1
Const ForWriting = 2
	
strTxtFile = "TEXT FILE PATH"
strMatch = Chr(34)
strNewText = ""

'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strTxtFile, ForReading)
strAllLines = objFile.ReadAll
objFile.Close

strNewText = Replace(strAllLines,strMatch,strNewText)

Set objFile = objFSO.OpenTextFile(strTxtFile, ForWriting)
objFile.WriteLine(strNewText)
objFile.Close

'====================================================================
'					END OF REMOVES QUOTES
'====================================================================



'====================================================================
'					REMOVES TABS
'====================================================================


Dim strAllLines,strTxtFile,strMatch,objFSO,objFile,strNewText
Const ForReading = 1
Const ForWriting = 2
	
strTxtFile = "TEXT FILE PATH"
strMatch = vbTab
strNewText = ""

'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strTxtFile, ForReading)
strAllLines = objFile.ReadAll
objFile.Close

strNewText = Replace(strAllLines,strMatch,strNewText)

Set objFile = objFSO.OpenTextFile(strTxtFile, ForWriting)
objFile.WriteLine(strNewText)
objFile.Close

'====================================================================
'					END OF REMOVES TABS
'====================================================================

Open in new window

Author

Commented:
Hi max...thanks for your quick response...is there a way to combine them into a single script?
Follows the merged script

Dim strAllLines,strTxtFile,strMatch,strMatch2,objFSO,objFile,strNewText
Const ForReading = 1
Const ForWriting = 2
	
strTxtFile = "TEXT FILE PATH"
strMatch = Chr(34)
strMatch2 = vbTab
strNewText = ""

'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strTxtFile, ForReading)
strAllLines = objFile.ReadAll
objFile.Close

strNewText = Replace(strAllLines,strMatch,strNewText)
strNewText = Replace(strAllLines,strMatch2,strNewText)

Set objFile = objFSO.OpenTextFile(strTxtFile, ForWriting)
objFile.WriteLine(strNewText)
objFile.Close

Open in new window