in reply to Printing line before matching expression
Hope you would be interested in this!
open (INPUT, $ARGV[0]) or die "I couldn't get at input text"; open (SAME_INPUT, $ARGV[0]) or die "I couldn't get at input text"; open (OUTPUT, '>outfile.txt') or die "Can't write to outfile: $!"; while ($line = <INPUT>) { if (( $line =~ /index_1/ ) and ($line =~ /6/)) { $index = $.-2; } } while ($line = <SAME_INPUT>) { if ($. == $index) { print OUTPUT $line; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Printing line before matching expression
by Laurent_R (Canon) on Sep 11, 2013 at 11:48 UTC | |
by uday_sagar (Scribe) on Sep 11, 2013 at 14:04 UTC |