Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How to convert a CR+LF (DOS/Windows) to LF (Unix)?

$
0
0

Hi everyone,

I work on T-SQL and have no idea about VBScripts. I'm trying to do a bcp on SQL Server. However, the file I'm bcp'ing is writing CRLF to the file. I'll be moving this file later to an Unix environment which only accepts LF. I've searched online and couldn't find any script that I can run on a Windows environment to remove the CRLF in the file. Could you please help me if there is a better solution to do this?

Here is one of the script I found online which doesn't seem to be working.

Dim fileTranOK

Function Main()

Dim sFile, tFile
	fileTranOK = True
	sFile = GlobalVariables("dPath")  &  GlobalVariables("dFLog1")
	tFile = GlobalVariables("dPath")  &  GlobalVariables("dFLog1") & ".temp"
	ManageFileContent sFile, tFile
End Function


Function ManageFileContent(sFile, tFile)

Dim oFSO, objFile, inFile, outFile, sText1, sText2, catLine
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set inFile = oFSO.OpenTextFile(sFile, 1)
	Set objFile = oFSO.CreateTextFile(tFile) 
	set objFile = nothing
	Set outFile = oFSO.OpenTextFile(tFile, 2)  
	Do While Not inFile.AtEndOfStream
		sText1 = inFile.ReadLine

		If (InStr(1,sText1, vbCr & vbLf)) Then
			Replace(sText1, vbCrLf, vbLf)
			outFile.WriteLine(sText1)
		End If
	Loop
	inFile.Close
	outFile.Close
	oFSO.DeleteFile sFile

	oFSO.MoveFile tFile,sFile

Set oFSO = nothing

End Function
PS: I know there are bunch of commands on UNIX to change this but I'd like to do this as part of my SQL Server job without any third party tool.

Thanks,

Bangaaram


Known is a DROP, Unknown is an OCEAN.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>