Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

An example am trying to understand from website. People2.txt is as follows.

2323:Doe John California

827:Doe Jane Texas

982982:Neuman Alfred Nebraska

I don't get the output as shown from the command below.

*PS C:\ Get-Content people2.txt | %{$data = [regex]::split($_, '\t|:'); Write-Output "$($data[2]) $($data[1]), $($data[3])"}

John Doe, California

Jane Doe, Texas

Alfred Neuman, Nebraska*

I could take out numbers and swapping first and second using

gc C:\appl\ppl.txt | %{$data = [regex]::split($_, ":") ;write-output $data[1] } | Out-File c:\appl\ppll.txt

gc C:\appl\ppll.txt | %{$data = $_.split(" "); Write-Output "$($data[1]) $($data[0]), $($data[2])"}

Please help

**Need to find more efficient ways to do this.

Also I want to understand '\t|:' - is it 'Split at first TAB stop and a : ' ?**

share|improve this question
1  
what are you trying to achieve? how would you like to have your output? –  user2141046 Jul 17 '13 at 13:03
    
What is the significance of $($data) enclosing a variable inside a variable ? –  user2591459 Jul 17 '13 at 13:08
    
Output should be like John Doe, California Jane Doe, Texas Alfred Neuman, Nebraska* –  user2591459 Jul 17 '13 at 13:08
add comment

1 Answer 1

Just threw this off the top of my head: ^(?<number>\d+):(?<first>\w+)\s+(?<last>\w+)\s(?<location>.*)$

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.