tiver43809
IS-IT--Management
I don't know much about scripting. I am trying to sort a text file from the last couple of digits of each line. I have gotten a sort to work (kinda) I ahve included the script I have been working with. And at the bottom a small sample of data. Now this sorts my file, but how would I go to the end of line and count back and sort on the s=##? The Sample I included word wrapped. It starts with AD and ends wiht s=# or s=##. It would be ok if the other ones did not get sorted or get written back to file. I can clean them up before I run the script.
ANY help sure would be Appreciated.
Const adVarChar = 200
Const MaxCharacters = 255
Const ForReading = 1
Const ForWriting = 2
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "ComputerName", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
DataList.AddNew
DataList("ComputerName") = strLine
DataList.Update
Loop
objFile.Close
DataList.Sort = "ComputerName"
DataList.MoveFirst
Do Until DataList.EOF
strText = strText & DataList.Fields.Item("ComputerName") & vbCrLf
DataList.MoveNext
Loop
Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt", ForWriting)
objFile.WriteLine strText
objFile.Close
***sample data
CV
AD,F3,undefined,undefined
AD,F2,undefined,undefined
AD,F1,undefined,undefined
AD,F3, 5,feuds
AD,F4,e=5513,l= 5,n=Oratemarco,acy,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2356,l= 5,n=Orney,poarlene,c=0.00,y=0.00,z=0,o=0,s=6
AD,F4,e=2499,l= 5,n=PXSITING,feudS,c=0.00,y=0.00,z=0,o=0,s=12
AD,F4,e=2344,l= 5,n=PXgnali,RtsaMikdnpo,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2079,l= 5,n=PXsiting,vrgtners,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2202,x=4202,l= 5,n=PXsitng t,PXsit cat,t=feud,w=23rd flr,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=5574,l= 5,n=VollBMiler,Merryl,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2456,x=4456,l= 5,n=BMBER,MikdnBERT,t=feud,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2929,x=4929,l= 5,n=BMMED,CONIxeLTING,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2256,l= 5,n=BMber,Mikdnbert M.,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=210,x=310,l= 10,n=BlackBMll,DaPXd M,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=292,x=392,l= 10,n=Block,DaPXd,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=2039,l= 10,n=Bogomolny,Jude,c=0.00,y=0.00,z=0,o=0,s=9
AD,F4,e=291,x=391,l= 10,n=runnnan,YRtndcia A,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=4103,x=4103,l= 10,n=Lkcci,Gsaegg,c=0.00,y=0.00,z=0,o=0,s=2
AD,F4,e=5594,x=4694,l= 10,n=LuMDKSCO,MICHAEL,c=0.00,y=0.00,z=0,o=0,s=8
AD,F4,e=5545,x=4645,l= 10,n=CHARkcmeS,IxeSAN,t=ASSOC,w=undefined,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2034,x=4034,l= 10,n=MerN,nvmERINE,t=Assoc.,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2708,x=4708,l= 10,n=fpOTE,Rredf,t=ASSC.,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2744,x=4744,l= 10,n=MDKIG,ANNEMARIE,t=ASSC.,c=0.00,y=0.00,z=0,o=0,s=9
AD,F4,e=282,x=382,l= 10,n=Lucey,ChristophJ,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=2815,x=4815,l= 10,n=Charles,Mikdnse,t=ASSOC,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=239,x=339,l= 10,n=Charters,ElizOrethR,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=2734,l= 10,n=Cho,BMndy,t=Apbl,c=0.00,y=0.00,z=0,o=0,s=14
AD,F4,e=2554,x=4554,l= 10,n=ohriston,Midfaael,t=Assoc.,c=0.00,y=0.00,z=0,o=0,s=7
AD,F4,e=4157,l= 10,n=diebnstein,enodken,c=0.00,y=0.00,z=0,o=0,s=2
ANY help sure would be Appreciated.
Const adVarChar = 200
Const MaxCharacters = 255
Const ForReading = 1
Const ForWriting = 2
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "ComputerName", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
DataList.AddNew
DataList("ComputerName") = strLine
DataList.Update
Loop
objFile.Close
DataList.Sort = "ComputerName"
DataList.MoveFirst
Do Until DataList.EOF
strText = strText & DataList.Fields.Item("ComputerName") & vbCrLf
DataList.MoveNext
Loop
Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt", ForWriting)
objFile.WriteLine strText
objFile.Close
***sample data
CV
AD,F3,undefined,undefined
AD,F2,undefined,undefined
AD,F1,undefined,undefined
AD,F3, 5,feuds
AD,F4,e=5513,l= 5,n=Oratemarco,acy,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2356,l= 5,n=Orney,poarlene,c=0.00,y=0.00,z=0,o=0,s=6
AD,F4,e=2499,l= 5,n=PXSITING,feudS,c=0.00,y=0.00,z=0,o=0,s=12
AD,F4,e=2344,l= 5,n=PXgnali,RtsaMikdnpo,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2079,l= 5,n=PXsiting,vrgtners,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2202,x=4202,l= 5,n=PXsitng t,PXsit cat,t=feud,w=23rd flr,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=5574,l= 5,n=VollBMiler,Merryl,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2456,x=4456,l= 5,n=BMBER,MikdnBERT,t=feud,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2929,x=4929,l= 5,n=BMMED,CONIxeLTING,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2256,l= 5,n=BMber,Mikdnbert M.,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=210,x=310,l= 10,n=BlackBMll,DaPXd M,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=292,x=392,l= 10,n=Block,DaPXd,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=2039,l= 10,n=Bogomolny,Jude,c=0.00,y=0.00,z=0,o=0,s=9
AD,F4,e=291,x=391,l= 10,n=runnnan,YRtndcia A,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=4103,x=4103,l= 10,n=Lkcci,Gsaegg,c=0.00,y=0.00,z=0,o=0,s=2
AD,F4,e=5594,x=4694,l= 10,n=LuMDKSCO,MICHAEL,c=0.00,y=0.00,z=0,o=0,s=8
AD,F4,e=5545,x=4645,l= 10,n=CHARkcmeS,IxeSAN,t=ASSOC,w=undefined,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2034,x=4034,l= 10,n=MerN,nvmERINE,t=Assoc.,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2708,x=4708,l= 10,n=fpOTE,Rredf,t=ASSC.,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=2744,x=4744,l= 10,n=MDKIG,ANNEMARIE,t=ASSC.,c=0.00,y=0.00,z=0,o=0,s=9
AD,F4,e=282,x=382,l= 10,n=Lucey,ChristophJ,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=2815,x=4815,l= 10,n=Charles,Mikdnse,t=ASSOC,c=0.00,y=0.00,z=0,o=0,s=0
AD,F4,e=239,x=339,l= 10,n=Charters,ElizOrethR,t=Plate,c=0.00,y=0.00,z=0,o=0,s=4
AD,F4,e=2734,l= 10,n=Cho,BMndy,t=Apbl,c=0.00,y=0.00,z=0,o=0,s=14
AD,F4,e=2554,x=4554,l= 10,n=ohriston,Midfaael,t=Assoc.,c=0.00,y=0.00,z=0,o=0,s=7
AD,F4,e=4157,l= 10,n=diebnstein,enodken,c=0.00,y=0.00,z=0,o=0,s=2