0

i have a csv file "emp.csv" with following information.

empid   status
1   t
2   a
3   t
4   t
5   a

I need empid and status of employees having status="t" and the output should be in "res.csv" file

1 Answer 1

5

For this, you'll first want to import the existing data with Import-Csv - but since your file is technically a TSV (tab-separated instead of comma-separated), make sure you specify this with -Delimiter "`t":

$employeeStatusData = Import-Csv .\path\to\emp.csv -Delimiter "`t"

Import-Csv will parse the input file and store the resulting objects in $employeeStatusData. To filter these object based on the value of the status property/column, use Where-Object:

$filteredEmployeeData = $employeeStatusData |Where-Object status -eq 't'

Now that you have the relevant rows selected, you can export the data again with Export-Csv:

$filteredEmployeeData |Export-Csv .\path\to\res.csv -Delimiter "`t" -NoTypeInformation
Sign up to request clarification or add additional context in comments.

1 Comment

Nice, didn't know about the tab delimiter! Thanks for this :)

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.