Creating a regex expression

Good morning all!!

In my code I and looking through file /etc/syslog.congf and printing every line that has /var/log in it. I need to turn the if 9$line) into a regex code instead.

 #!/usr/bin/perl
 
  @file= 'cat /etc/syslog.conf';   //when 
 
  foreach $line (@file){
  if ($line =~ '/var/log'){
  print $line;
  }
  }

Thanks in advance for some help!! Would: if ($line =~ /?var*log?/) work?

Ben

You need to match the line correctly (with literals and wildcards, etc). It seems you are only matching an optional '/' and then the literal string 'va' and then zero or more 'r' (greedy) and then the literal string 'lo' and then an optional 'g'.... which is not correct.

First of all, is '/var/log/*' always at the beginning of the line? What comes after?

It is always best to post the text in the file or variable you are trying to match so any member who wants to reply can test what they are doing against the text, not just incomplete fragments.

Hi ,
Try this

if ($line =~ /\/var\/log/) { print $line ;}

Pravin-thanks so much it works!! I had that earlier but then got confused with the /

Ben