Script task to the rescue. Assuming your flat file has uniform delimiters per line i.e. each row in the file are separated by say comma, the way to go about would be -
- Drag a Script Task transformation and pass the file path of the input flat file
- Start reading the file line by line.
- Withing the loop, get the occurrences of delimiter (you can use a Split function to get the count) as a Key and the the whole row as a Value. Store this result set in a dictionary object.
- Get the max value of Keys from the dictionary using the Dictionary.Keys.Max() function. (Basically the highest number of delimiter occurrences per line) and store it in a variable say MaxCount.
- Now loop through each Key/Value pair. For each line having Key value less than the MaxValue, append empty empty delimiters i.e. say if the Max delimiter per line is 5 and in the line there are only 2, use a for each loop to append additional 3 blank delimiter i.e. ',,,'.
- Using a StreamWriter get all the Values of the dictionary into a new file.
You would need to using System.IO and System.LINQ classes to achieve this. When using in SSIS 2008, ensure the Project Framework is set to 3.5 for it to work.
The new file would then be of uniform length.