Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Substitution For 'ps -aux | Grep [P]ROCESS'

DZone's Guide to

Substitution For 'ps -aux | Grep [P]ROCESS'

·
Free Resource
as we know, invoking grep after ps with first letter of the PROCESS enclosed in brackets [] (like this: ps -aux | grep [P]ROCESS), excludes grep PROCESS from the output. so, instead of typing those brackets manualy every time, we may use the code below:

FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps -aux | grep "[$FIRST]$REST"


you may use it as separate shell-script -- like this:

#!/bin/sh
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps -aux | grep -v "full/path/to/your/script" | grep "[$FIRST]$REST"


or just include it in your .bashrc or similar -- like this:

function psg
{
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps -aux | grep "[$FIRST]$REST"
}
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}