#!/usr/bin/perl use strict; use warnings; my $filename = '/home/david/Programming/Perl/data/var.txt'; #So you can use diamond operator and inplace editing push @ARGV, $filename; #Enable inplace editing. Copy of input file saved as 'var.txt.bk' $^I = ".bk"; my $replaced = 0; while(<>){ chomp; if ($replaced == 0 and s/the line to be replaced/this is the new line/){ $replaced++; } print "$_\n"; }
In reply to Re: search one instance
by d5e5
in thread search one instance
by toniax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |