Guest User

Untitled

a guest
Jan 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3.  
  4. open IN, "<", "Delete_line.txt"
  5. or die " Can not open the file $!";
  6. open OUT, ">", "Update_delete_line.txt"
  7. or die "Can not write in the file $!";
  8.  
  9. my ($total_line, $line, $number, $printed_line);
  10.  
  11. print"Enter the number of line to be deleten";
  12. $number = <STDIN>;
  13.  
  14. while ($line = <IN>) {
  15.  
  16. $total_line = $.; # Total number of line in the file
  17. }
  18.  
  19. $printed_line = $total_line - $number;
  20.  
  21. while ($line = <IN>) {
  22.  
  23. print OUT $line unless $.== $printed_line;
  24. }
  25.  
  26. use File::ReadBackwards qw( );
  27.  
  28. my $num_lines = 10;
  29. my $qfn = 'file.txt';
  30.  
  31. my $pos = do {
  32. my $fh = File::ReadBackwards->new($qfn)
  33. or die $!;
  34. $fh->readline() for 1..$num_lines;
  35. $fh->tell()
  36. };
  37.  
  38. truncate($qfn, $pos)
  39. or die $!;
  40.  
  41. #!/usr/bin/env perl
  42. use strict;
  43. use warnings;
  44. use Tie::File;
  45. tie my @lines, 'Tie::File', 'myfile' or die "$!n";
  46. $#lines -= 10;
  47. untie @lines;
  48.  
  49. #!/usr/bin/perl
  50.  
  51. my @cache;
  52. my $n = shift @ARGV;
  53.  
  54. while(<>) {
  55. push @cache, $_;
  56. print shift @cache if @cache > $n;
  57. }
  58.  
  59. perl -ne'BEGIN{$n=shift@ARGV}push@c,$_;print shift@c if@c>$n' NUMBER
  60.  
  61. use strict;
  62. use warnings;
  63.  
  64. use Tie::File;
  65. tie my @file, 'Tie::File', 'filename' or die "$!";
  66.  
  67. $#file -= 10;
  68.  
  69. open my $filehandle, "<", "info.txt";
  70. my @file = <$filehandle>;
  71. splice(@file, -10);
  72. print @file;
  73.  
  74. use English qw<$INPLACE_EDIT>;
  75.  
  76. { local @ARGV = $name_of_file_to_edit;
  77. local $INPLACE_EDIT = '.bak';
  78. my @buffer;
  79. for ( 1..$num_lines_to_trim ) {
  80. push @buffer, <>;
  81. }
  82.  
  83. while ( <> ) {
  84. print shift @buffer;
  85. push @buffer, $_;
  86. }
  87. }
  88.  
  89. my @buffer;
  90. my $limit_reached = 0;
  91. edit_file_lines {
  92. push @buffer, $_;
  93. return ( $limit_reached ||= @buffer > $num_lines_to_trim ) ? shift @buffer
  94. : ''
  95. ;
  96. } $name_of_file;
  97.  
  98. my $num_lines = 10;
  99. my $qfn = 'file.txt';
  100.  
  101. system('head', '-n', -$num_lines, '--', $qfn);
  102. die "Error" if $?;
  103.  
  104. #!/usr/bin/perl -w
  105. use strict;
  106.  
  107. open(my $in,"<","Delete_line.txt") or die "Can not open the file $!";
  108. open(my $out,">","Update_delete_line.txt") or die"Can not write in the file $!";
  109.  
  110. print"Enter the number of lines to be deleten";
  111. my $number=<STDIN>;
  112.  
  113. my @file = <$in>;
  114.  
  115. for (my $i = 0; $i < $#file - $number + 1; $i++) {
  116. print $out $file[$i];
  117. }
  118.  
  119. close $in;
  120. close $out;
Add Comment
Please, Sign In to add comment