@outlines = `ps -ef | grep $logname`;
Then, I would capture what you want with the regex, not the pre-match. Note that you can avoid excessive escaping in the regex by using alternate delimiters, m{}:
use strict; use warnings; my $logname = 'mylogname'; while (<DATA>) { if (m{(.*/export/home/$logname)/.*/bin/.*}) { print $1, "\n" } } __DATA__ root 28834 28833 0 Aug25 ? 00:00:00 login -- mylogname2 root 29853 29852 0 Aug25 ? 00:00:00 login -- mylogname2 root 5379 5378 0 Aug26 ? 00:00:00 login -- mylogname2 root 5454 5453 0 Aug26 ? 00:00:00 login -- mylogname2 509 6710 1 0 00:20 ? 00:00:28 /export/home/mylogname/folder1/bin/binar +y 509 6729 1 0 00:35 ? 00:00:11 /export/home/mylogname/folder2/bin/binar +y 522 7996 1 0 07:00 ? 00:00:07 /export/home/mylogname2/folder1/bin/bina +ry 509 7997 1 0 07:00 ? 00:00:01 /export/home/mylogname/folder3/bin/binar +y 522 8045 1 0 07:02 ? 00:00:02 /export/home/mylogname2/folder4/bin/bina +ry
prints:
509 6710 1 0 00:20 ? 00:00:28 /export/home/mylogname 509 6729 1 0 00:35 ? 00:00:11 /export/home/mylogname 509 7997 1 0 07:00 ? 00:00:01 /export/home/mylogname
Is this the output you are looking for?
Update: Please re-read How do I compose an effective node title?.
In reply to Re: Retrieve "ps -ef" strings using regex
by toolic
in thread Retrieve "ps -ef" strings using regex
by Raoul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |