[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

help creating a batch file to automate removal of double quotes and clean a text file

Hello, I need some help creating a batch file to automate the process of removeing double quotes in 2 text file, it gets exported from crystal reports, can be renamed any name. the double quotes are in the beggining of the files, middle and at the end of the files. also need to removes 2 spaces to join two lines into one line. output file needs to have a different name , such as today's date, so it's doesnt get overwritten. example is attached in the text file. this should be ONE line and all the quotations are removed.

http://box.net/huslayer 

 


example.txt
0
Jason Yousef, MS
Asked:
Jason Yousef, MS
1 Solution
 
Patmac951Commented:
It would be easier to simply write a quick program to do this but if you have to use a batch file, this link should provide you with the necessary command syntax you need to accomplish this.
http://www.dostips.com/DtTipsStringManipulation.php#Snippets.Remove
0
 
mlmccCommented:
Can you control the export from Crystal?

mlmcc
0
 
Shift-3Commented:
Paste the script below into a text file with a .vbs extension.  Customize the value of the strInput variable on line 5 with the location of the input file.  Customize the value of the strOutut variable on line 6 with the location of the output file to create.

Running the script will create a new text file with all quote characters removed and all lines joined into one.


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
End Function

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Jason Yousef, MSSr. BI  DeveloperAuthor Commented:

Shift-3,

Thank you so much, that worked great, but it joined all the lines together, even the next records, it basically removed all the spaces, but the example files was having only one record, so when i run it on the actual file,it joined all the lines.

is there a way we can join the only first 2 lines, and each new line starts with the "ZE3" ?

Thank you so much for your help
appreciate your help
0
 
Jason Yousef, MSSr. BI  DeveloperAuthor Commented:
This is another example, i've included more than 1 record, sorry if the other one was a misleading example.
 
all the lines needs to be shiffted and only started with the "ZE3......."
 
Thanks in advance for any help...

example2.txt
0
 
Jason Yousef, MSSr. BI  DeveloperAuthor Commented:
I've been able to get help from a friend modifying Shift-3  code to this :
 

Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
strInput = "stix.txt"
strOutput = "stix" & 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
 
 
my only concern that i don't understand the difference or the addition i mean...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 Shift-3, you're the best
 
0
 
Jason Yousef, MSSr. BI  DeveloperAuthor Commented:
Sorry that was a stupid question...
It's easier than what i thought
 
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

 
lol, thanks for everybody that tried to help or even looked at my question
Shift-3 thanks a zillionnnnnn
0
 
Jason Yousef, MSSr. BI  DeveloperAuthor Commented:
Thanks
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now