Solved

How do I strip out a second CR/LF pair that randomly appears in a flat file

Posted on 2013-05-21
6
695 Views
Last Modified: 2016-02-10
Hi!

I'm using SSIS to import some flat files.  They are fixed length and use a CRLF as a row delimiter.  However, there are some cases (like every 5000 lines) where there is a second CRLF pair.  This messes up my import and rejects a number of records.  I'm trying to figure out a way to remove any occurrences of <CR><LF><CR><LF> to just be <CR><LF>   Any suggestions?
0
Comment
Question by:ITMikeK
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39185149
ok, this is what I will do, I will try to use a script component and replace the double crlf charecter with a single one.

the below code might be of some use (note this is not tested, so test it yourself and let us know)

 Dim data As String
 data = file.ReadToEnd()
data = data.replace(ControlChars.CrLf+ControlChars.CrLf,ControlChars.CrLf)

 Dim writer As New System.IO.StreamWriter(Dts.Variables("@[User::str_SourcePath]").Value.ToString(), False)
 writer.Write(data)
 writer.Flush()
 writer.Close()

Open in new window

0
 

Author Comment

by:ITMikeK
ID: 39185188
Shouldn't this be possible using the REPLACE transformation function with a derived column?   I'm wrestling with the syntax, but would be something like this:

COLUMN ALIAS: ENDOFROW

REPLACE(ENDOFROW,"\n\n","\n")   ?
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39185198
No, because SSIS will determine your end of row by the CRLF character.
SO, by the time the your replace function actually gets hit then SSIS might have converted the data from your file into rows and it might be struggling to assign the values to columns, where it might fail ( as there is an empty line where there are two carriage returns).

So, you have to do that before loading the file using the below script task.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:ITMikeK
ID: 39185286
i haven't written a SSIS script before, but I am a proficient C# developer.  How would I add the script?  When I drop the component on my canvas and double click to edit it, it launches a new instance of VS and another solution.  Not sure how to proceed.
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39185302
Cool, I am a novice in SSIS too, so cannot help you out much here....
If I am with same issue then I will a C# executable which will convert the crlf+crlf charecters into one crlf charecter from the C# console program and add this to the calling script of SSIS as well...
0
 

Author Closing Comment

by:ITMikeK
ID: 39188615
I was able to strip out the offending characters with Notepad++ in about 30 seconds.  When I have more time, I'll look at automating this into a script.  Thanks for the direction.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
query question 12 32
SSMS Opening Mode 9 18
Where is the Help Section? 8 25
.NET Enums [Flags] & Bitwise Design Question 6 26
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question