开发者

perl regexp problem 2

开发者 https://www.devze.com 2023-01-28 03:46 出处:网络
I have a list of command to parse... like: > ls -lart > ls > ls /etc/passwd > ping > ping 127.0.0.1

I have a list of command to parse...

like:

> ls -lart 
> ls 
> ls /etc/passwd 
> ping 
> ping 127.0.0.1
> PING
> LS

I have to开发者_开发知识库 count the number of times ls and ping was executed, I have to not count uppercase variant like LS and PING, but I have to count command launch with option like "ls -lart"

How to check if a line contain the exact word ls or ping or whatever?

With regular expression!!!

Thanks,


my $count = 0;

while (<STDIN>) {
  m/^\s*(ls|ping).*$/;
  $count++ if $1;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消