0

I have already done many searches and have not found a clear way to do it. there are many variations of how people are removing contents in a text file but not the way I need it to be done.

I have a watch folder that has about 22 text file dropped every 30 minutes. I need to be able to run something that deletes the first 3000 lines in those text file.

I have other task performing to those files and using task scheduler to trigger batch files at a certain time.

So running it on schedule is no issue.

My issue is I cannot find a way to remove 3000 lines from each of the text files, without copying, deleting or changing the other content.

Does anyone know how to remove 3000 lines from a text file? I can get the loop to find all the text file no issue, jut doesn't know the command to remove lines.

1 Answer 1

2

I would just use powershell for this. This example removes the first 3000 lines from a single test.txt file.

$file = "test.txt"
$remo = get-content $file
$remo[3000..$remo.count] | set-content $file

If you feel comfortable with batch file, you could just loop the above powershell into batch to do this to each file..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.