LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 19 Sep 2007 13:13:00 -0400
Reply-To:     Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:      Re: OT: ruby solution to 'Re: How do I sort tokens in a variable'
              task
Comments: To: Roy Pardee <pardee.r@GHC.ORG>

On Wed, 19 Sep 2007 08:38:38 -0700, Pardee, Roy <pardee.r@GHC.ORG> wrote:

>Can't resist sharing this ruby solution, which uses approach 1. > > input = File.open("c:/temp/original_data.txt", "r") > output = File.open("c:/temp/fixed_data.txt" , "w") > > input.each_line do |this_line| > output.puts(this_line.chomp.split("+").sort.join("+")) > end > > input.close > output.close ...

can't resist sharing that there are many modern scripting languages that can pull this off. :-) Here is an ms jscript example. save it as sort.js and call it at the command line like: cscript sort.js

------ fs = new ActiveXObject("scripting.filesystemObject");

inf = fs.OpenTextFile("c:\\temp\\original_data.txt", 1); // forReading outf = fs.OpenTextFile("c:\\temp\\fixed_data.txt", 2, true); // forWriting

while (!inf.AtEndOfStream) { outf.WriteLine(inf.ReadLine().split("+").sort().join("+")); }

inf.Close(); outf.Close(); ------


Back to: Top of message | Previous page | Main SAS-L page