in reply to Re^2: Help editing a file based off seach criteria
in thread Help editing a file based off seach criteria

You could use a loop instead of using grep, and keep a counter to remember the line number, or just remember not only the current line but also the line before it.

my @list = <DATA>; chomp @list; my $prev_line; for my $line (@list) { # Look at current line # remember this line as "previous" };

Replies are listed 'Best First'.
Re^4: Help editing a file based off seach criteria
by perlnewb123 (Sexton) on Jan 13, 2009 at 15:52 UTC
    Same thing here, this tells me each time what line the search criteria will be in, even when the file grows, but how do I jump up one line if the pattern is matched?
    #!/usr/bin/perl open DATA, "</home/file.conf"; while (<DATA>) { if(m/\END\b/) { print "$.\n"; } } close(DATA);

      Now, what line number could the line have that is right before the current line (whose number you know)?

        pos--;