Remove lines from csv

I have a 5 GB csv file.
I need to remove all lines with a predefined phrase.
How do I do that?;)
Who is Participating?
QlemoConnect With a Mentor Batchelor and DeveloperCommented:
You can't remove lines from a file (as you can append data). The file needs to get copied to apply changes.
If you do not need to know anything about the particular data, and just can try to match strings:
get-content C:\SourceFile.csv |
  ? { $_ -notlike '*Phrase to detect*' } |
  set-content C:\DestinationFile.csv

Open in new window

PleaseAnswerAuthor Commented:
I'll give it a go, thanks!
Another approach would be
(gc orig-file.csv) -notmatch "string you expect to delete" | out-file clean-file.csv

Open in new window

WEBINAR: GDPR Implemented - Tips & Lessons Learned

Join the WatchGuard team on Thursday, March 29th as we recount some valuable lessons learned in weighing the needs of a business against the new regulatory environment, look ahead at the two months left before implementation, and help you understand the steps you can take today!

QlemoBatchelor and DeveloperCommented:
-match is dangerous because a phrase might contain characters like . () and more which have special meaning.
-match looks for a match inside a string and supports regexes
-like looks for a match inside a string and supports wildcards

I think the reverse might be true, where a like statement due to wildcards could yield multiple false positives while match looks for a pure pattern match.

I will however yield to your wisdom on this.
QlemoBatchelor and DeveloperCommented:
I don't think it makes a difference in the end, but without me knowing that phrase, who can tell?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.