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);
1
  • While we have traditionally welcomed questions about sysadmin-level scripting, this sort of question is really a better fit for Stack Overflow or Unix & Linux
    – voretaq7
    Apr 27, 2012 at 6:54

1 Answer 1

2

This should to the trick:

if ($sessionWeb =~ /(\d+ active Sessions)/) {
  print $1."\n";
}
2
  • It is printing the entire html page
    – Arun
    Apr 27, 2012 at 6:45
  • The above code extracts only the requested part. There must be a bug in your code.
    – Oliver
    Apr 27, 2012 at 6:49

Not the answer you're looking for? Browse other questions tagged .