How do I sort a Delimited text file by the second delimitation?

I have a text file that is laid out as such:

aaaa aaa (2000)
bbb bbb bb (2001)
cccc,ccc (1999)
ddd dddddd (2004)

I would like to be able to make a VBScript that sorts the text file and makes a new csv from it that has it in order by (*). That way it would list back:

cccc,ccc (1999)
aaaa aaa (2000)
bbb bbb bb (2001)
ddd dddddd (2004)

I tried a couple times using some other scripts but I am pretty new at this and figured I should reach out for help.

Thank you for any help you could give.


May 26th, 2015 2:27pm

The script request form is here:

https://gallery.technet.microsoft.com/scriptcenter/site/requests

This forum is for specific questions rather than script requests.

Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 2:33pm

Your file is too odd to be easily converted.  You need to use a real file and not one you have made up.

Start by learning how too use VBScript (I recommend skipping vbscript for PowerShell.

Start here: https://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx?f=255&MSPPError=-2147217396

May 26th, 2015 2:44pm

Here is an example of why it won't work:

PS C:\scripts> $file
col1,col2,col3
aaaa,aaa,(2000)
bbb,bbb,bb,(2001)
cccc,ccc,(1999)
ddd,dddddd,(2004)
PS C:\scripts> $file|ConvertFrom-Csv

col1 col2   col3
---- ----   ----
aaaa aaa    (2000)
bbb  bbb    bb
cccc ccc    (1999)
ddd  dddddd (2004)


PS C:\scripts> $file|ConvertFrom-Csv|sort col3

col1 col2   col3
---- ----   ----
cccc ccc    (1999)
aaaa aaa    (2000)
ddd  dddddd (2004)
bbb  bbb    bb


Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 2:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics