Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove quotation from a txt file using an automated script 1

Status
Not open for further replies.

Huslayer

IS-IT--Management
Jan 4, 2010
15
US
Hello,
I need some help creating a batch file to automate the process of removeing double quotes in a text file.

the double quotes are in the beggining of the file and at the end of the file.

also in the middle and removes 2 spaces to join two lines into one line.

example is attached in the text file.
this should be ONE line and all the quotations are removed.

hey! it's for my job, so paid adivse and helkp are accepted ! being fair :)
 
What have you tried so far and where in your code are you stuck ?
Have a look at the FileSystemObject and the Replace function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH,

Thank you so much for your propmet replay, whoever i'm not into programming, i'm in management and trying to automate the procedure that i'm doing.

I started by reading online how to checkfor the source file and create the output file with the current date and time, but no luck so far
 
I've went this far
--------------------

Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

strInput = "c:\example.txt"
strOutput = "c:\" & ShortDateTime(Now) & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objInput = objFSO.OpenTextFile(strInput, ForReading, False, TriStateUseDefault)
arrText = Split(objInput.ReadAll, vbCrLf)
strText = Join(arrText, "")
strText = Replace(strText, Chr(34), "")
objInput.Close

Set objOutput = objFSO.OpenTextFile(strOutput, ForWriting, True)
objOutput.Write strText
objOutput.Close

Function ShortDateTime(dtmTime)
strYear = Year(dtmTime)
strMonth = Right("0" & Month(dtmTime), 2)
strDay = Right("0" & Day(dtmTime), 2)
strHour = Right("0" & Hour(dtmTime), 2)
strMinute = Right("0" & Minute(dtmTime), 2)
strSecond = Right("0" & Second(dtmTime), 2)

ShortDateTime = strYear & strMonth & strDay & "-" & strHour & strMinute & strSecond


---------------------------

but the problem is the script joins all the lines, i've uploaded another example that includes more than 1 record.

it really joined all the lines together !! missed up the whole file, I want to star each line by "Z3......."

any help is appreciated
Thanks in advance
 
Something like this ?
Code:
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
strInput = "D:\example.txt"
strOutput = "D:\" & ShortDateTime(Now) & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, ForReading, False, TriStateUseDefault)
arrText = Split(Replace(objInput.ReadAll, Chr(34), ""), vbCrLf)
objInput.Close
Set objOutput = objFSO.OpenTextFile(strOutput, ForWriting, True)
For i = 0 TO UBound(arrText) - 1 Step 2
  objOutput.WriteLine arrText(i) & arrText(i + 1)
Next
objOutput.Close

Function ShortDateTime(dtmTime)
  strYear = Year(dtmTime)
  strMonth = Right("0" & Month(dtmTime), 2)
  strDay = Right("0" & Day(dtmTime), 2)
  strHour = Right("0" & Hour(dtmTime), 2)
  strMinute = Right("0" & Minute(dtmTime), 2)
  strSecond = Right("0" & Second(dtmTime), 2)
  ShortDateTime = strYear & strMonth & strDay & "-" & strHour & strMinute & strSecond
End Function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH,

you're the best, thanks a zillion.

my only concern that i don't understand the difference or your addition...can you explain it please when you have a chance...

the reason i'm asking is I've a different report that comes in 5 lines this time!!!

i'll post example for the file "EXAMPLE3.TXT"

Thanks again sooooooooooo much

 
I've a different report that comes in 5 lines
Code:
...
For i = 0 TO UBound(arrText) - 4 Step 5
  objOutput.WriteLine arrText(i) & arrText(i + 1) & arrText(i + 2) & arrText(i + 3) & arrText(i + 4)
Next
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Lol, that was easy ....for you I mean...
Thanks again, it worked wonderfully for me...

i'll start reading more about VBScripting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top