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?;)
Thanks!
PleaseAnswerAsked:
Who is Participating?
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
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

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

Open in new window

0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
-match is dangerous because a phrase might contain characters like . () and more which have special meaning.
0
 
becraigCommented:
-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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I don't think it makes a difference in the end, but without me knowing that phrase, who can tell?
0
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.