DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Substitution For 'ps -aux | Grep [P]ROCESS'
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"
}






Comments
Snippets Manager replied on Tue, 2010/04/13 - 7:21am
Snippets Manager replied on Mon, 2010/06/21 - 5:37am
psg () { ps aux | grep "[${1:0:1}]${1:1}" }