Remove a line from a CSV powershell
-
19-06-2021 - |
سؤال
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.
المحلول
This command should work:
gc file.txt | ? { $_ -notlike '*----*' } | sc file2.txt
It essentially performs the following tasks:
- Retrieves the content of
file.txt
- Filters (using
Where-Object
) content for lines not like ---- - Writes the remaining content to
file2.txt
لا تنتمي إلى StackOverflow