How can I extract employee names and salaries from a text file?

0
7
Asked By TechWiz99 On

I'm working with a text file named emp.txt that contains employee data, including their ID, name, age, date of joining, department, and salary. I'm looking to display only the employee names along with their respective salaries. Here's a snippet of the contents:

Empid Empname Age DOJ Dept Salary
101 Sam 45 22-Nov-2008 IT 50000
102 Ram 38 14-Jan-2010 Accounts 40000
103 Tim 46 15-June-2005 IT 60000
104 Kim 25 03-Sep-2020 IT 50000
105 Jane 27 27-Oct-2018 Purchase 30000
106 Dane 36 07-Feb-2014 Accounts 35000
107 Raj 50 17-Mar-2005 Accounts 50000
108 Kiran 28 15-June-2015 IT 55000
109 Varun 40 10-Jul-2011 Purchase 40000
110 Tarun 47 14-Aug-2007 Purchase 50000

Can someone help me solve this?

3 Answers

Answered By ScriptingNinja On

It seems like you're asking for an easy way out here. The fun is really in figuring things out for yourself! If you check out the Select-Object command, it should help you out. Here's a link that explains it: [Select-Object Documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7.5).

Answered By PowerShellPro On

Here’s a way to get the info you’re looking for: `Import-Csv -Path "emp.txt" -Delimiter " " | Select-Object Empname, Salary`. Just keep in mind that relying too much on easy answers can hold you back in the long run.

User123 -

I tried running that command, but the compiler isn't retrieving the employee name and salary properly. What could be the issue?

Answered By CodeGuru88 On

Before diving into the solution, it would be great to see what you've tried so far. Have you attempted any code to solve this? Showing your work can help others assist you better.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.