0

I need a code the deletes the first row in a CSV file (the row is also empty). I am using the code below to get the CSV file I need and delete tne content in the first cell, which is "users". But when I delete the content the cell remains empty. What I need is either a way to delete the whole row or maybe shift the entire column up after deleting "users"? Don't know if that works...

Get-Content C:\TEMP\test\File1.csv |
    % { $_ -replace 'users', '' } |
    Set-Content C:\TEMP\test\file2.csv
3
  • 1
    Get-Content input.csv | Select-Object -Skip 1 | Set-Content output.csv Commented Mar 18, 2019 at 9:51
  • Are you sure you want to delete a row and not a column (_ I need to delete the content in the first cell, which is "users"_)? Show us part of your csv file, the first two or three lines would be enough. Make sure you change the real names, email addresses and such to fake ones before editing your question. Commented Mar 18, 2019 at 15:47
  • thank you for the reply @Theo, the one-liner above did the trick just fine :) Commented Mar 19, 2019 at 13:29

1 Answer 1

1

I'm not sure, but i think what you want is to remove the first column (users) of the File1.csv file and output a new csv file with all columns, except this users columns.

Suppose your input csv file (file1.csv) looks something like this:

"users","email","morestuff"
"John Doe","[email protected]","blah"
"Jane Doe","[email protected]","more blah"

and what you want to do is remove the users column so file2.csv will become this:

"email","morestuff"
"[email protected]","blah"
"[email protected]","more blah"

then this one-liner should do it:

(Import-Csv -Path 'C:\TEMP\test\file1.csv' | Select-Object * -ExcludeProperty Users) | Export-Csv -Path 'C:\TEMP\test\file2.csv' -NoTypeInformation
Sign up to request clarification or add additional context in comments.

Comments

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.