in reply to Re^2: search for a string and return previous relating string if found
in thread search for a string and return previous relating string if found
In that case then glob would find the files
poj#!/usr/bin/perl use strict; my $dir = 'c:/temp/tmp'; # directory to search my @files = glob("$dir/*.txt"); for my $filename (@files){ my $lineno = 0; print "Scanning $filename ..\n"; open IN,'<',$filename or die "Could not open $filename : $!"; my $iface; while (<IN>){ ++$lineno; if (/^interface\s+(.*)/){ $iface = $1; } if (/spanning-tree guard/){ print "$filename,$lineno,$iface,$_"; $iface = ''; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: search for a string and return previous relating string if found
by haukex (Archbishop) on Dec 07, 2017 at 18:33 UTC |