[Kc] RegExes
Emmanuel Mejias
emmanuel.mejias at gmail.com
Mon Mar 31 18:34:58 PDT 2008
On Mon, Mar 31, 2008 at 8:29 PM, Emmanuel Mejias <emmanuel.mejias at gmail.com>
wrote:
> hey guys, I'm trying to match two patterns, say */var/log/ *from
> /etc/syslog.conf, using regexes? but I don't want to match every line with
> log (Logging, log) which is what I'm getting. I tried just matching /var/,
> but I was trying for two patterns. what would be the correct way?
>
> code:
>
> #!/usr/bin/perl -w
>
> @input = `cat /etc/syslog.conf`;
>
> foreach $line (@input) {
> if ($line =~ */[varlog]/*){
> print $line;
> }
> }
>
> I want my output to look something like this....
>
> *.info;mail.none;authpriv.none;cron.none /var/log/messages
> authpriv.* /var/log/secure
> mail.* -/var/log/maillog
> cron.* /var/log/cron
> uucp,news.crit /var/log/spooler
> local7.* /var/log/boot.log
>
>
> not like this....
>
> # Log all kernel messages to the console.
> # Logging much else clutters up the screen.
> #kern.* /dev/console
> # Log anything (except mail) of level info or higher.
> # Don't log private authentication messages!
> *.info;mail.none;authpriv.none;cron.none /var/log/messages
> # The authpriv file has restricted access.
> authpriv.* /var/log/secure
> # Log all the mail messages in one place.
> mail.* -/var/log/maillog
> # Log cron stuff
> cron.* /var/log/cron
> # Everybody gets emergency messages
> *.emerg *
> # Save news errors of level crit and higher in a special file.
> uucp,news.crit /var/log/spooler
> # Save boot messages also to boot.log
> local7.* /var/log/boot.log
>
>
I think I figured it out. How's that look, better?
#!/usr/bin/perl -w
@input = `cat /etc/syslog.conf`;
foreach $line (@input) {
if ($line =~* /\var\/log/*){
print $line;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/kc/attachments/20080331/64625617/attachment.html
More information about the kc
mailing list