Rewriting Text File by rearranging headings

NICK COLLINS
NICK COLLINS used Ask the Experts™
on
Hello,

I would like some help to rewrite a text file based on two entries..

Example

Heading 1, Heading 2
Liverpool Men, Liverpool Ladies
Everton Men, Everton Ladies
Arsenal Men, Arsenal Ladies

So I would like the text file to be rearranged by moving the headings..

New Text File

Heading 2,  Heading 1
Liverpool Ladies, Liverpool Men
Everton Ladies, Everton Men
Arsenal Ladies, Arsenal Men

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
I removed the extraneous space that's usually not present in a .CSV, but if you want to add it in you can simple change the -join string to ", ".
Get-Content somefile.txt | ForEach-Object `
{
    (($_ -split ",").Trim())[1,0] -join ","
} | Out-File anotherfile.txt

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial