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
Solved

Remove lines from csv

Posted on 2015-01-11
6
79 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 69

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 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 69

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 69

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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