Truncating text files to a certain number of lines

  • I've created a text log file in a package to hold execution results, but it's growing in size at an alarming rate. I need to be able to refer to the info in the file, so I don't want to stop it exporting the results to the file, however I would like to limit the number of lines it's exporting at present. As time goes on the earlier logged entries are of less importance to me so I think I can truncate the length of the log file. However I'm not sure what the best method is to delete the first x number of lines from the text file apart from importing in to a sql table and and using a select top command to write out the lines. Seems a bit over the top that though. Any ideas please?

  • Instead of writing to a text file, why not write to a table where each row has a "create date"?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Is there no way of doing what I'm trying to do with text files though?

  • You mean withing T-SQL? Sure... import the file... delete the desired rows... export the file. You could also write some VBS using the System File Object to do it for you and use xp_CmdShell to execute it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • OK then, so a workaround within SSIS rather than a function of SSIS it sounds. Thanks for your assistance here Jeff.

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

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