Link to home
Start Free TrialLog in
Avatar of SLPowers
SLPowersFlag for United States of America

asked on

Look for a word in a CSV and remove everything under it using powershell

I have a line in a csv called examples.
I want to remove that line and every line under it using powershell.  

What is the best way to accomplish this?

Thanks
Avatar of oBdA
oBdA

Your question is not quite clear. Do you have a line called examples in a csv file, or do you have some line in a csv file called examples?
I'm leaning towards the former, so try this:
$InputFile = "C:\Temp\test.csv"
$OutputFile = "C:\Temp\test-NoExamples.csv"
$StopLine = "Examples"
Get-Content $InputFile | % {If ($_ -ne $StopLine) {$_} Else {Break}} | Set-Content $OutputFile

Open in new window

If the latter: is "the line" a regular csv line, and how do you want to identify the line in question; as the full text line, as part of a text line, as properties of the csv columns, ...?
Avatar of SLPowers

ASKER

Thanks so much for the fast reply.  I am sorry for my poorly worded question.


I have a large CSV file.   Somewhere down the file will be a Row and in column A row (something)  the word "Examples" will be there.

I want to delete the word examples and every row below that.

Thanks again
User generated image
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked perfectly!


Thanks