1

How to delete lines containing a specific character in a text file with PowerShell?

Input file example:

12314+000000 00000000
20 300 1238238948023
A+A+000000 00000000
20 500 1238238948023

Output file example:

20 300 1238238948023
20 500 1238238948023

So it will delete lines containing + or specific characters or words.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
haryoe
  • 43
  • 1
  • 3

1 Answers1

4

The simplest way is to use new file to write data in it:

Get-Content "D:\test.txt" | Where-Object {$_ -notmatch '\+'} | Set-Content "D:\out.txt"

That will give:

20 300 1238238948023
20 500 1238238948023

In out.txt.

This is used in this answer and this

Community
  • 1
  • 1
gofr1
  • 15,741
  • 11
  • 42
  • 52