Best way to grab first and last record from a file?

  • I have a inbound, pipe delimited, file. The first and last records contain audit information pertaining to the file. I want to extract these out and throw them into a table. The number of columns varies between the header, body, and trailer columns, but are a fixed amount between the three. 5, 71, 6. Any advice on how I can split this up?

    Any help would be appreciated.

  • In PowerShell 3.0 and higher you could use the following:

    Test.txt

    First

    something

    something else

    Last

    $filename = 'C:\work\test.txt'

    Get-Content $filename -Head 1

    Get-Content $filename -Tail 1

  • I haven't used much PowerShell, but I appreciate the input. I'll check this out.

  • You don't need powershell if you don't want it.

    An article in doing this in SSIS with scripts:

    http://www.blue-chip.com.au/ssis-file-with-header-detail-trailer.aspx

    Basically reads the file as non delimited and parses it in a script task.

  • Nevyn (11/13/2013)


    You don't need powershell if you don't want it.

    An article in doing this in SSIS with scripts:

    http://www.blue-chip.com.au/ssis-file-with-header-detail-trailer.aspx

    Basically reads the file as non delimited and parses it in a script task.

    It's actually a script component rather than a script task.

    Other than that, it looks like a good reference. As long as you do not need the information in the final row before you read the data rows.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply