Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. @files = ();
  4.  
  5. if($ARGV[0] =~ /^-[0-9]+$/){
  6. $n = $ARGV[0];
  7. $n =~ s/-//g; #removes - from -n
  8. shift @ARGV;
  9. }else {
  10. $n = 10;
  11. }
  12. foreach $arg (@ARGV){
  13. if ($arg eq "--version"){
  14. print "$0: version 0.1\n";
  15. exit(0);
  16. #handle other options
  17. }else{
  18. push @files, $arg;
  19. }
  20. }
  21. foreach $f (@files){
  22. open(F,"<$f") or die "$0: Can't open $f:$!\n";
  23. #process F
  24. #...
  25. if(@files >1){
  26. print "==> $f <==\n";
  27. }
  28. $num_lines = `cat < $f | wc -l | egrep -o "[0-9]+"`;
  29. # $num_lines2 = split " ", $num_lines;
  30. # print "num lines = $num_lines\n\n";
  31. $g = 1;
  32. while($line = <F>){
  33. if($g > ($num_lines - $n)){
  34. print $line;
  35. }
  36. $g++;
  37. }
  38. close(F);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement