วันพฤหัสบดีที่ 12 มกราคม พ.ศ. 2555

awk basic

awk is very useful tool for linux user.
For example, you have output from ps aux like this :

#ps aux 

root      2213  0.0  0.4   6596  2428 pts/2    S    12:08   0:00 bash
root      2235  0.0  0.1   4848   952 pts/2    S+   12:08   0:00 /bin/bash xxx
root      2236  0.0  0.6   7132  3236 pts/2    S+   12:08   0:04 ssh xxx

The second column is PID, and 8th is process state.
To find the zombie process you just execute the following command  :

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z


See just use $th of the column, you will get the value of that column. Also, you can apply even you have comma separated field with -F option.

For more usage of this command please consult
#man awk

:)