Remove lines from text file if it starts with

Question:

I have large text files that contain invalid records.

I would like to remove all lines where the first field is blank. The file delimiter is a tilde , so essentially I want to remove all lines where the first character is ~

Can someone assist with the PowerShell code – I cannot seem to get it right.

Answer:

Just adding the answer part from my comment as an answer, so that people can see that the question has been answered.

The solution which worked from the person asking the question was:

As a note, be aware of potential encoding issues. If you need to specify encoding, both the Get-Content and the Set-Content methods have an -Encoding parameter which you can use to specify encoding.

Source:

Remove lines from text file if it starts with by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply