in reply to Deleting and replacing lines in a file
I assume you've already set up your script to read the file and write the changed results somewhere else. Something like this if you were reading from standard input and writing to standard output:
If that's the case and you always want to do something to lines 1, 2, and 3, you could just use a counter:while (<>) { # edit line if needed. print $_; }
my $line = 0; while (<>) { ++$line; next if ($line < 3); # skip first two lines s/XXXX/YYYY if ($line == 3); # change third line print $_; }
|
|---|