Reputation: 1120
From ps command I want to have some var in that case "PS1" to be defined and after that everything till that var to be deleted.
ex.:
ps -ef | grep -i PS1
cbsuser 1138700 1 0 Sep 15 - 0:10 ./PS1 PS01 3
expected output:
./PS1 PS01 3
In my mind is something like which is wrong:
sed 's/^$/ "PS1"/g'
or related I'm not sure how to finish it.
Upvotes: 1
Views: 90
Reputation: 3380
A few options. These all parse your command. A better approach is to use pgrep
or the o
option for ps
but if you really want to parse:
grep itself
ps -ef | grep -Po 'PS1.*'
perl
ps -ef | grep -i PS1 | perl -pe 's/.*(?=PS1)//'
sed
ps -ef | sed 's/.*\(PS1.*\)/\1/'
Upvotes: 2
Reputation: 4628
You can use custom format for ps
to output only what you need so you only need to filter for the required command in the list:
ps e --format %a | grep PS1
Or even better use pgrep
that is designed to do this if it's available:
pgrep -fl PS1 | cut -f2- -d' '
Upvotes: 2
Reputation: 785691
You can simplify with using pgrep
:
pgrep -fl PS1 | cut -d ' ' -f2-
Upvotes: 0
Reputation: 908
ps -ef | grep -i PS1| grep -v grep| awk '{print $(NF-2)" "$(NF-1)" "$NF}'
Upvotes: 0