in reply to Extracting Lines of a text file
#!/usr/bin/perl use strict; print "Enter the txt\n"; my ($input,@ss,$i); chop($input=<STDIN>); open(FILE,"txt.txt") or die $!; @ss=<FILE>; close(FILE); foreach $i(0 .. scalar @ss){ if($ss[$i] =~ /$input/) { if($i ne 0){print "$ss[$i-1]";} print "$ss[$i]"; print "$ss[$i+1]"; } }
|
|---|