Reputation: 11
Ok, first off I am a absolute total noob with PS so I apologize for my ignorance now.
I have a .csv file which I am importing and (I believe) am stripping out the headers which is what I want, I am then trying to save it again as the same .csv
here is what I am using to import it into PS, and the on screen input does not show the headers so I know the -Skip 1 is working and for my education I played with that value and it's working.
$file = "C:PATH\Okta NO 2K.csv"
$data = import-csv $file
$data | ConvertTo-Csv -NoType | Select-Object -Skip 1
What I am having issues with is how to then export the data back into a .csv with the only change being the headers being removed. A few things I have done has change the format from data in every tab (every cell) to various tables which is not what I need. I appreciate any help.
Upvotes: 1
Views: 758
Reputation: 15480
I can use this:
(get-content $file)|select -skip 1|set-content $file
As the suggestion by @Andrew
But the only problem is that here whenever you will import the modified csv it will take the first row as header, so it could not be imported without headers. So you need a duplicate header using -Header
or other things
Note the need to use ()
to enclose get-content
so that it reads the whole file into memory first, which is required if you want to save back to the same file as part of the same command.
Upvotes: 1