简体   繁体   中英

How to deal with pipe as data in pipe delimited file

I am trying to solve a problem where my csv data looks like below:

A|B|C 
"Jon"|"PR | RP"|"MN"
"Pam | Map"|"Ecom"|"unity"
"What"|"is"this" happening"|"?"

That is, it is pipe delimited and has quotes as text qualifier but it also has pipe and quotes with in the data values. I have already tried

Update based on the comments

I tried to select | as delimiter and " as Text Qualifier but when trying to import data to OLEDB Destination i receive the following error:

couldn't find column delimiter for column B

You have to change the Column Delimiter property to | (vertical bar) and the Text Qualifier property to " within the Flat File Connection Manager

在此处输入图片说明

在此处输入图片说明

If these is still not working then you have some bad rows in the Flat File Source which you must handle using the Error Output:

I actually ended up writing ac sharp script to remove the initial and last quote and set the column delimiter to quote pipe quote ("|") in SSIS. Code was as below:

public void Main()
    {
        String folderSource = "path";
        String folderTarget = "path";

        foreach (string file in System.IO.Directory.GetFiles(folderSource))
        {
            String targetfilepath = folderTarget + System.IO.Path.GetFileName(file);
            System.IO.File.Delete(targetfilepath);
            int icount = 1;
            foreach (String row in System.IO.File.ReadAllLines(file))
            {
                if (icount == 1)
                {
                    System.IO.File.AppendAllText(targetfilepath, row.Replace("|", "\"|\""));

                }
                else
                {

                    System.IO.File.AppendAllText(targetfilepath, row.Substring(1, row.Length - 2));
                }
                icount = icount + 1;
                System.IO.File.AppendAllText(targetfilepath, Environment.NewLine);
            }
        }

        Dts.TaskResult = (int)ScriptResults.Success;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM