user438596
user438596

Reputation: 35

What am I missing in this Perl search string to make it match?

I have a large file that is full of text lines that I want to parse out specific data from. A sample line of the data I want is:

results:    IF-MIB::ifInOctets.9 = Counter32: 23212027

where the value of Counter32 changes and the if*.Octets.\d changes. I don't mind needing multiple 'if' statements to get the data if needed, but I have been unable to determine what i'm missing. i've checked perl reference docs and regex help docs and am unable to see what I am missing.

here is a sample of what i have (the base form of which works in other projects i am working on):

my $line = $_;
#print $line;
if ($line =~ "/result.*ifOutOctets\.6.* = counter32/i"){
print $line; #this is here only for testing to see if I am matching the line since the file is not filling in

I have tried using the following lines in the if($line =~"") location and I am sure i am missing something simple but can't find what it is:

/result(.*)ifOut(.*) = counter32/i
/result.*ifOut.* = counter32: (\d*)/i
/result.*IF-MIB::ifOut.*(\d*) = counter32: (\d*)/i

I have a Mac here that I used for testing via grep and it is returning results successfully using this form:

grep -i "result.*ifOutOctets.* = counter32" fileName

Upvotes: 2

Views: 148

Answers (1)

nobody
nobody

Reputation: 20163

In Perl you don't quote the regex. Corrected code is:

my $line = $_;
if ($line =~ /result.*ifOutOctets\.6.* = counter32/i)
{
    # do whatever
}

Upvotes: 3

Related Questions