Posted By

heinz1959 on 06/11/10


Tagged

lines bbedit Unsort


Versions (?)

Unsort Lines BBEdit Unix Filter


 / Published in: Perl
 

URL: http://www.commandlinefu.com/commands/view/4401/randomize-lines-opposite-of-sort

Need to "unsort" / randomize / scramble LINES in a text? Copy source -> then BBEdit -> File -> New -> Text Document -> paste source -> save as "Unsort Lines.pl" to ~/Library/Application Support/BBEdit/Unix Support/Unix Filters/ --- done

  1. #!/usr/bin/perl -wl
  2.  
  3. @f=<>;
  4.  
  5. for $i (0 .. $#f) {
  6. $r=int rand ($i+1);
  7. @f[$i, $r]=@f[$r,$i] if ($i!=$r);
  8. }
  9.  
  10. chomp @f;
  11.  
  12. print join $/, @f;

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: pfudd on October 14, 2010

See also 'sort -R' in GNU coreutils 8.4 (available on Fedora 13 linux).

You need to login to post a comment.