View Single Post
Old 01-09-2008   #5 (permalink)
Powershellnewbie


Vista Business 32bit
 
 

Re: do something for each token in a line separated by comma

Hello,

I have a very similar issue that is fairly straight forward with a batch file, but I would like to learn a simpler cleaner version with Powershell.

We have text files that look like this -

johndoe@abccompany.com,janedoe@abcco...abccompany.com,

etc.

all on one line of text. We want to just strip out the username (everything before the @ symbol) and nothing more then put them into a new text file 1 per line. (or to excel, since Powershell can do this)
The problem that I have been encountering is that when I try something like this -

$a = Get-Content ("\\network location\long_names.txt")
$b = $a.split('@')

I get a result that looks like this -

johndoe
abccompany.com,janedoe
abccompany.com,xyzuser
abccompany.com,somebody

etc.

Is there a way to only get the username and put it into new file with one username per line?

I am very new to PowerShell but am starting a 20 hour course, so hopefully I'll know more soon. Any help would be appreciated. We have already accomplished this with a batch file that we wrote up in 30 mins or so, but it would be nice to see these real world examples able to be accomplished with Powershell.

Thanks!
My System SpecsSystem Spec