?
Solved

Remove lines from csv

Posted on 2015-01-11
6
Medium Priority
?
85 Views
Last Modified: 2015-01-13
I have a 5 GB csv file.
I need to remove all lines with a predefined phrase.
How do I do that?;)
Thanks!
0
Comment
Question by:PleaseAnswer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40543235
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
 

Author Comment

by:PleaseAnswer
ID: 40543276
I'll give it a go, thanks!
0
 
LVL 29

Expert Comment

by:becraig
ID: 40543301
Another approach would be
(gc orig-file.csv) -notmatch "string you expect to delete" | out-file clean-file.csv

Open in new window

0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 70

Expert Comment

by:Qlemo
ID: 40543356
-match is dangerous because a phrase might contain characters like . () and more which have special meaning.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40543379
-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
 
LVL 70

Expert Comment

by:Qlemo
ID: 40543391
I don't think it makes a difference in the end, but without me knowing that phrase, who can tell?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question