in reply to Grepping a File
If you want the specific line that contains the given value, either treat the file data as an array of lines, or else change how you are looking for the target string:
# (no need to change how $buff is assigned) # option 1: my ( $result ) = grep( /28/, split( /\n/, $buff )); my $target = ( split( / /, $result )[1]; # get 2nd token from matched + line # option 2: my ( $target ) = ( $buff =~ /(\S+)\s+28\n/ );
In the latter approach, if " 28\n" occurs more than once in the file, only the first occurrence is captured to $target.
|
|---|