Remove last few words from Line

Hi I would like to remove last few words from File

Could anybody Help on it.

ps -ef | grep mgr.prm | awk '{print $10}'
/opt/app/dummyd/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm

I want output like

/opt/app/dummyd/xyz
/opt/app/dummyab/xyz
/opt/app/dummydcdd/xyz

Help Appreciated.

Try:

ps -ef | grep mgr.prm | awk '{print $10}' | sed 's!/dirprm/mgr\.prm$!!'
1 Like

Try

ps -ef | grep mgr.prm | awk -F"/" 'NF-=2' OFS="/"

Sample Output

$ cat <<eof | awk -F"/" 'NF-=2' OFS="/"
/opt/app/dummyd/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
eof

/opt/app/dummyd/xyz
/opt/app/dummy/xyz
/opt/app/dummy/xyz

Thanks bartus11 , It really worked.

I don't get it. Where did the characters marked in red above come from?

I can understand wanting to remove the final two components of the selected pathnames, but I don't understand the logic that seems to produce random characters that do not appear in the input. Also, you said you wanted to remove a few words. Pathname components are not usually described as "words". And, is a few always two, or is there something else you haven't told us?