#!/usr/bin/perl # filesubset -- by greenfly # This program randomly chooses a subset of the lines in a file given as input, and outputs those lines to the screen # # usage: # filesubset # $infile = shift @ARGV; open INFILE, "$infile"; @input = ; close INFILE; $lines_to_output = int(rand $#input); %lines_outputted = {}; for($i = 0; $i < $lines_to_output; $i++) { $current_line = int(rand $#input); while($lines_outputted{$current_line}) { $current_line = int(rand $#input); } print $input[$current_line]; $lines_outputted{$current_line} = 1; }