<pre name="code" class="html">[root@wx03 ~]# cat -n aaa
1 3`13
2 edqae
3 daa
4 313
5 1313
6 1
7 AAAhash1
8 e31
9 dad
10 fad
11 AAAA
12 32131
13 AAA
14 qe
15 dad
16 AAA
17 fdaaf
18 fafa
19 AAAhash2
[root@wx03 ~]# cat q1.pl
my @arr=();
open (LOG ,"<","aaa");
while (<LOG>) {
if ($_ =~/AAA/){$num=$.;push (@arr,$num); $hash{$num}=$_;};
};
print $arr[0]."
";
print $hash{$arr[0]}."
";
print $arr[-1]."
";
print $hash{$arr[-1]}."
";
[root@wx03 ~]# perl q1.pl
7
AAAhash1
19
AAAhash2