Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use my awk shortcut as a function, so that I can pass the column number which then prints me the output. My aliases are:

alias A="| awk '{print \$1}'
alias G="| grep -i'

Instad of typing:

ps -ef | grep mysql | awk 'print $2'

I want to be able to type this:

ps -ef G mysql A 2

Any suggestions? Thank you!

share|improve this question
For a completely different approach, try pgrep -f mysql (assuming pgrep is available). – jw013 Jul 27 '12 at 17:04
nice tool thx!! – DannyRe Jul 27 '12 at 17:13
Indeed. And for arbitrary fields, ps -o <field> $(pgrep mysql). – Mikel Jul 27 '12 at 17:22
or ps h -o %p -C mysqld if you want the PIDs of a particular named process (-C is exact match, not search pattern or regexp). You can have multiple -C args, e.g. ps h -o %p -C mysqld -C mysql to get client and server processes. – cas Jul 27 '12 at 21:06

I don't think it's possible. Basically, aliases can't take arguments ($1), and functions can't do macro expansion (|).

The closest options I can think of:

in bash or zsh

C() { col=$1; shift; eval "awkcmd='{ print \$$col }'"; echo "$awkcmd"; "$@" | awk "$awkcmd"; }

C 2 ps -ef G mysql

in zsh

alias -g F="| tr -s '[[:space:]]' | cut -d ' ' -f"

ps -ef G mysql F 2
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.