ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: How do you sort and remove duplicates lines from a file ?
Date Wed, 02 Jul 2008 08:00:57 GMT
 

-----Original Message-----
From: Paul Taylor [mailto:paul_t100@fastmail.fm] 
Sent: Tuesday, July 01, 2008 11:48 PM
To: Matt Benson
Cc: Ant Users List
Subject: Re: How do you sort and remove duplicates lines from a file ?


With the example of Matt it's getting clearer, but
like Scot i never used the <concat> task, like Paul i feel it's
not very intuitive to use.


Personally i would prefer a little <script>, but that's a matter of
taste

reading, sorting and writing to another file =

<script language="ruby">
<![CDATA[
  File.open("sorted.txt", "w") do |file|
    File.readlines("sort.txt").uniq.sort.each do |line|
      file.write(line.chomp<<"\n")
    end
  end
]]>
</script>


echoing, setting a property =

<script language="ruby">
<![CDATA[
  linesarr = File.readlines("sort.txt").uniq.sort.collect {|line|
line.chomp<<"\n"}
  puts "Sorted Lines => " + linesarr.to_s
  $project.setProperty "sortedfile", linesarr.to_s
]]>
</script>


(chomp and afterwards appending \n again for the case
when there's no linefeed after last line, that would result in
two lines on one after sorting)

Regards, Gilbert



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message