I am importing a text file with 5 fields. However the 5th field is an open text format and records carriage returns.
The file is comma delimited, and each new line of data will start with defined text (PD), is it possible to use the replace command to search the fifth field of each "PD" row in the text file and remove the carriage returns to have a clean file?
I found this macro and it seems to do something close, but replaces all the carriage returns in the whole file and not just the 5th field.
Here is example of what is received:
"username","access_time","dbname","object_name","command"
"PDR1","Mar 28 2011 9:56AM ","DB1","","update master set
Master= 3,
Units =6,
lug = 9"
"PDC1","Mar 28 2011 9:56AM ","DB1","","update R_New set
Master= 62,
Units= 7,
Post = 81"
This is what I need it to look like:
"username","access_time","dbname","object_name","command"
"PD9R1","Mar 28 2011 9:56AM ","DB1","","update master set Master= 3, Units =6, lug = 9"
"PD9C1","Mar 28 2011 9:56AM ","DB1","","update R_New set Master= 62, Units= 7, Post = 81"
This is the code I found, but does not completely work...
The file is comma delimited, and each new line of data will start with defined text (PD), is it possible to use the replace command to search the fifth field of each "PD" row in the text file and remove the carriage returns to have a clean file?
I found this macro and it seems to do something close, but replaces all the carriage returns in the whole file and not just the 5th field.
Here is example of what is received:
"username","access_time","dbname","object_name","command"
"PDR1","Mar 28 2011 9:56AM ","DB1","","update master set
Master= 3,
Units =6,
lug = 9"
"PDC1","Mar 28 2011 9:56AM ","DB1","","update R_New set
Master= 62,
Units= 7,
Post = 81"
This is what I need it to look like:
"username","access_time","dbname","object_name","command"
"PD9R1","Mar 28 2011 9:56AM ","DB1","","update master set Master= 3, Units =6, lug = 9"
"PD9C1","Mar 28 2011 9:56AM ","DB1","","update R_New set Master= 62, Units= 7, Post = 81"
This is the code I found, but does not completely work...
Code:
Sub line_Removal()
'
Dim strFile As String
Dim strBuffer As String
Dim ff As Integer
strFile = "C:\testing\*.log"
strBuffer = Space(FileLen(strFile))
ff = FreeFile
Open strFile For Binary Access Read As #ff
Get #ff, , strBuffer
Close #ff
strBuffer = Replace(strBuffer, Chr(13), "")
Kill strFile
Open strFile For Binary Access Write As #ff
Put #ff, , strBuffer
Close #ff
'
End Sub