1

I currently have the following csv

These, Are, Several, Columns
-----, ---, -------, -------
"And", "here", "is", "data"
"And", "some", "more", "data"

While I wish I could simply change the process that creates the csv to remove the line of dashes that isn't possible.

The line of dashes is always the 2nd line, can I use powershell to remove the 2nd line of data?

Bonus question, I'm looking to add at the bottom a blank line, followed by a paragraph of text. I'm guessing I would be able to use the add-content cmdlet, but I'm not entirely sure how.

1 Answer 1

1

This command should work:

gc file.txt | ? { $_ -notlike '*----*' } | sc file2.txt

It essentially performs the following tasks:

  1. Retrieves the content of file.txt
  2. Filters (using Where-Object) content for lines not like ----
  3. Writes the remaining content to file2.txt
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the edit. I was just about to go look up what each section did. Any chance you could help with that adding a paragraph into the csv?
Yeah, just like you said: Add-Content -Path File2.txt "BACKTICKnParagraph of text with a new lineBACKTICKngoes here just like this." Replace "BACKTICK" with an actual backtick. The BACKTICKn represents a new line.
am I able to save back into file.txt?
Remove-Item File.txt; Move-Item File2.txt File.txt;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.