[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: change file contents using perl

Anand D Sankruthi proclaimed:
> I have a set of 6 lines in a file. i want to replace all these lines by a
> set of new lines (which is a subset of the old lines). can any one tell me
> the easiest way of doing this using perl??

Without knowin what exactly "subset of the old lines" means...

#!/usr/bin/perl -i.bak

use strict;

my $i = 0;
my $line;

while ($line = <>) {
	chomp $line;
	if ($i >= 6) {
		print $line . "\n";
	} else {
		print "Some subset of line here\n";

You'll call this script like so:  foo.pl file_to_be_changed