windows script to remove LF and CR characters

May 4, 2009 at 01:15:00
Specs: Windows XP
I need a script to remove LF and CR Characters from a CSV file.
I have never written any widnows script. I need help.

the Data in my csv file looks like this.




Here there are 3 records and four columns. Ever column is seperated by a COMMA. If a column value is having a comma then that column is enclosed within DOUBLE QUOTES.

Please help me out


See More: windows script to remove LF and CR characters

Report •

May 4, 2009 at 03:53:22
So it should look like this, right?


If at first you don't succeed, you're about average.


Report •

May 4, 2009 at 04:16:13
yes.. I want tht output.. Can it be done?

Report •

May 7, 2009 at 00:34:01
Hi I tried wirting a VB Script like this..

Const ForReading = 1
Const ForWriting = 2

strFileName = "HRD.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

strText = objFile.ReadAll

strNewText = Replace(strText, vbCr, "$$$$")
'strNewText = Replace(strNewText, "$$$$", vbCrLf)

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

This is removing the CRs but also LF. Converting all the records into one single record. I know im close to resolving this issue..but im missing something..

I believe it can be resolved if i can write a VBscript with thee following logic.

1.	Open the File.
2.	Read the file line by line.
3.	For each line identify each  character.
4.	Check if that character is Double Quotes(")
5.	If its Double Quotes  then 
6.	Check for each charcter if its a CR or LF
7.	If its Double Quote then exit this loop.
8.	Repeat the Step 5 to 7 until you reach the EOF.
9.	Save the Modified File
10.	Close the File

Is this logic implemetable?

Report •

Related Solutions

May 23, 2009 at 10:54:51

Hi vibhutidevatraj

(You) need a script to remove LF and CR Characters from a CSV file.

I have the perfect script for you. I will assume the csv file is at C:/folder1/file1.csv.

# Read the contents of csv file into a string variable.
var string content ; cat "C:/folder1/file1.csv" > $content

# Remove all line feeds (LF) .
while ( { sen "^\n^" $content } > 0 )
    sal "^\n^" "" $content > null

# Remove all carriage returns (CR) .
while ( { sen "^\r^" $content } > 0 )
    sal "^\r^" "" $content > null

# Write the file back.
echo $content > "C:/folder1/file1.csv" 

The script is written in biterscripting. You can translate this functionality in any language, including DOS.

If you use biterscripting
- Install if from - it is free.
- Save the above script in C:\Scripts\csv.txt.
- Call the script with the following command in biterscripting.

script csv.txt

- In biterscripting, you can specify a path with a / or with a \ .
- You can also schedule the following command in your task scheduler to run this (or any script) periodically.

C:\biterScripting\biterScripting.exe csv.txt


Report •

Ask Question