Solved

Remove lines from csv

Posted on 2015-01-11
6
75 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
  • 3
  • 2
6 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 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 28

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 68

Expert Comment

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

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 68

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now