############################################################################### ## File decimater # # Decimates a file on line basis. Reads an input file and generates an # output file that is a stripped version of the input. The stripped file # contains the following lines from the input file: # line 1 # line 1 + lines_to_skip # line 1 + 2*lines_to_skip # ... # # Usage: dcmate # # Author: L. Hollevoet ############################################################################### #!/usr/bin/perl -w use strict; use GetOpt::Std; if (! $ARGV[0] =~ /\w+/ || ! $ARGV[1] =~ /\d+/){ print "\nUsage info: dcmate.pl \n\n"; exit(0); } my $file_in = $ARGV[0]; my $decimate_value = $ARGV[1]; my $file_out = $file_in; $file_out =~ s/\.(\w+)$/_stripped\.$1/; if (-e $file_in && -f $file_in){ open(IN , "<$file_in") || die "Could not open input file $file_in: $!\n"; open(OUT, ">$file_out") || die "Could not open output file $file_out: $!\n"; } else { die "Input file $file_in does not exist!\n"; } my $counter=0; while (){ if ($counter == 0){ print OUT; } if ($counter == $decimate_value){ $counter = 0; } else { $counter++; } } close (IN); close (OUT);