removing extra space in last row using ssis

2019-07-15 14:36发布

I have a csv file which contains few rows, columns. I am having issue at source because the last row has an extra space. How can i remove this space?

You can see the following image has an extra space at the end

you can see the attached image has an extra space at the end

1条回答
We Are One
2楼-- · 2019-07-15 15:26

Since you are open to powershell, I have used this method. It's important that the last think in each file is your LF/CR. If it could be missing then you'd have to put a check in there for that.

Single File

$stream = [IO.File]::OpenWrite("somefile.csv")
$stream.SetLength($stream.Length - 2)
$stream.Close()
$stream.Dispose()

Multiple Files in a directory

#Remove the last bit of data from the end of the file, which is a LF, so BULK INSERT doesn't break
$fileDirectory = "E:\dir\subdirectory"

foreach($file in Get-ChildItem $fileDirectory)
{
    $filePath = $fileDirectory + "\" + $file

    $stream = [IO.File]::OpenWrite($filePath)
    $stream.SetLength($stream.Length - 2)
    $stream.Close()
    $stream.Dispose()
}

I use this on a pretty large daily dataset and it's stupid fast, a second or two. Original idea credited to Joey via this answer.

FROM THE OP

Execute process Task Values

查看更多
登录 后发表回答