Issues replacing new line in PowerShell script

I have a CSV file which has the following for example:

data1,data2,data3,data4,data5
,,,,,
data6,data7,data8,data9,data0

New lines are CRLF (`r`n) as viewed in Notepad++.

I have this in my PowerShell script to remove the line with all commas:

(Get-Content $csvPath) | Foreach-Object {$_ -replace ",,,,,`r`n", ""} | Set-Content $csvPath2

The script will not detect the returns. Even if I remove the commas and just have `r`n. However, I can replace the commas with `r`n without issues.

How can I remove that entire line of commas so that it appears as below?

data1,data2,data3,data4,data5
data6,data7,data8,data9,data0

Answers


Use:

$lines = get-content C:\temp\test.txt | ?{$_ -notlike ",,,,*"}
$lines.count

Here the file test.txt contains:

data1,data2,data3,data4,data5
,,,,
data6,data7,data8,data9,data0

The output is:

data1,data2,data3,data4,data5
data6,data7,data8,data9,data0

Need Your Help

Deploy a rails app using MySQL to Heroku using ClearDB addon

mysql ruby-on-rails heroku cleardb

I have a Rails app called "enrollment_app" that initializes and populates all the tables in the database with a MySQL seed file. I built the app, added some migrations and pushed my app to Heroku.

MVC Contrib VerificationException

c# asp.net-mvc mvccontrib

I have read this post and I wanted to use ControllerExtensions.RedirectToAction method. But I have System.Security.VerificationException Which says: type argument '[MyController type]' violates the