smathew


does any one how to search for a word in a text file and return it back using the script task in ssis

the file may contain data like this

POSITION SMSMSS20051230000

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

what i am looking for is to be able to parse and get the date which is present in the first line "POSITION SMSMSS20051230000" as "20051230"

and then return that as a variable ..

Thanks for any help in advance

smathew





Re: searching for a word in a text file and retuning it using script taks in ssis

Will Riley


Take a look at the solution I managed to hack together myself here

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1583714&SiteID=1

If the date is always in the same place you could fashion a solution in the same way I guess....

Hope this helps







Re: searching for a word in a text file and retuning it using script taks in ssis

smathew

Thanks will...your script helped a lot... i modified it a bit so that it did not look only for the first letter in the line...to look for a particular word in a line and return the date based on that.... here is the code after modification

Public Sub Main()

Dim oStream As New IO.StreamReader(CStr(Dts.Variables("CompleteFilePath").Value))

Dim strReadLine As String, filedate As Date

While oStream.Peek <> -1

strReadLine = oStream.ReadLine()

If InStr(strReadLine, CStr(Dts.Variables("keyword").Value)) > 0 Then

filedate = New DateTime(CInt(Strings.Mid(strReadLine, 17, 4)), CInt(Strings.Mid(strReadLine, 21, 2)), CInt(Strings.Mid(strReadLine, 23, 2)))

Exit While

End If

End While

Dts.Variables("date").Value = CStr(filedate)

Dts.TaskResult = Dts.Results.Success

End Sub

CompleteFilePath is a variable that stores the file location---just made it more dynamic

keyword is a variable that is used to store the word that we would want to search...

I also changed the date variable to a String..

Anyways thanks a lot!!!

Sobby