1

How to grep the string in perl.

Variable sessionWeb contains a web page html code. I want to grep "active Sessions" from this and want to print as below. For example the line in the web page will be

"2 active Sessions, 0 passivated Sessions (more stats...)"

Expected Output:

2 active Sessions.

I have tried the following code but it is not working ?

 $sessionStr="active Sessions";
     $sessionCount =~ grep( /$sessionStr/,$sessionWeb);
Arun
  • 13
  • 1
  • 4
  • While we have traditionally welcomed questions about sysadmin-level scripting, this sort of question is really a better fit for [Stack Overflow](http://www.stackoverflow.com) or [Unix & Linux](http://unix.stackexchange.com) – voretaq7 Apr 27 '12 at 06:54

1 Answers1

2

This should to the trick:

if ($sessionWeb =~ /(\d+ active Sessions)/) {
  print $1."\n";
}
Oliver
  • 5,973
  • 24
  • 33