File: del_lines

package info (click to toggle)
creduce 2.6.0-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 4,328 kB
  • ctags: 4,312
  • sloc: cpp: 23,740; ansic: 6,970; sh: 4,827; perl: 2,680; lex: 441; makefile: 426
file content (34 lines) | stat: -rwxr-xr-x 728 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env perl
##
## Copyright (c) 2012 The University of Utah
## All rights reserved.
##
## This file is distributed under the University of Illinois Open Source
## License.  See the file COPYING for details.

###############################################################################

use strict;
use warnings;

use File::Temp;

die unless (scalar(@ARGV)==3);

(my $fn, my $command, my $number) = @ARGV;

(my $TMP, my $tmpfilename) = File::Temp->tempfile("tempXXXXX", 
						  UNLINK => 0);
open INF, "<$fn" or die;
my $count=0;
while (my $line = <INF>) {
    if ($count == $number) {
    } else {
	print $TMP $line;
    }
    $count++;
}
close INF;
close $TMP;
print "$tmpfilename\n";
system "mv $tmpfilename $fn";