 |
|
Using awk in UNIX
& Linux
Oracle Tips by Burleson Consulting
|
Also see
handy awk command examples.
Using awk in UNIX
The awk utility is especially useful for removing a specific column
of output from a UNIX command. For example, suppose we need to
create a list of UNIX process ID’s for all Oracle processes on our
server.
root> ps -ef|grep -i oracle|awk '{
print $2 }'
23308
25167
12193
25163
12155
24065
24073
Here we start by issuing the ps –ef command to get a list of all
UNIX processes, and then use grep to filter out all processes except
this that contain the string “oracle.
Finally, we use the awk utility to extract the second column of
output.
root> ps -ef|grep -i oracle
oracle 23308 1 0 May 14 ? 0:06 ora_lgwr_prodb1
oracle 25167 1 0 Apr 30 ? 0:26 ora_smon_prodc1
oracle 25163 1 0 Apr 30 ? 41:27 ora_lgwr_prodc1
oracle 12155 1 0 11:30:43 ? 0:01 oracleprodcars (LOCAL=NO)
oracle 24065 1 0 Apr 30 ? 0:02 ora_pmon_rman
oracle 24073 1 0 Apr 30 ? 10:39 ora_ckpt_rman
oracle 24846 1 0 May 11 ? 0:48 oracleprodc1 (LOCAL=NO)
root> ps -ef|grep -i oracle|awk '{ print $2 }'
23308
25167
12193
25163
12155
24065
24073
The awk
utility is used often extract a
specific column of data from output or a file.
For example, to create a list of UNIX process IDs for all
Oracle processes on the server.
root> ps -ef|grep -i oracle|awk '{ print $2 }'
23308 25167 12193 25163 12155 24065 24073
First, issue the ps
–ef
command to get a list of all
UNIX processes, and then use grep to
filter out all processes except this that contain the string “oracle.”
The awk
utility is used to extract the
second column of output.
root> ps -ef|grep -i oracle
oracle
23308 1
0 May 14 ?
0:06 ora_lgwr_prodb1
oracle 25167
1 0
Apr 30 ?
0:26 ora_smon_prodc1
oracle 25163
1 0
Apr 30 ?
41:27 ora_lgwr_prodc1
oracle 12155
1 0 11:30:43 ?
0:01 oracleprodcars (LOCAL=NO)
oracle 24065
1 0
Apr 30 ?
0:02 ora_pmon_rman
oracle 24073
1 0
Apr 30 ?
10:39 ora_ckpt_rman
oracle 24846
1 0
May 11 ?
0:48 oracleprodc1 (LOCAL=NO)
root> ps -ef|grep -i oracle|awk '{ print $2 }'
23308 25167 12193 25163 12155 24065
24073
|